From cb852a1c18d68722de659e852d927754082e8469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Kolsj=C3=B6?= Date: Mon, 19 Jan 2015 11:52:54 +0100 Subject: [PATCH 1/6] Don't delete everything in tmp while running integration tests. The test suite should not assume it owns the entire tmp dir. --- Gemfile.lock | 10 +++++----- test/integration_test.rb | 31 +++++++++++++++++-------------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index ccd6fab..bb7c9a8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -40,12 +40,12 @@ GEM guard-test (2.0.4) guard (~> 2.0) test-unit (~> 2.2) - httparty (0.13.0) + httparty (0.13.3) json (~> 1.8) multi_xml (>= 0.5.2) i18n (0.6.9) - json (1.8.1) - json_pure (1.8.1) + json (1.8.2) + json_pure (1.8.2) listen (2.5.0) celluloid (>= 0.15.2) celluloid-io (>= 0.15.0) @@ -56,9 +56,9 @@ GEM minitest (4.7.5) multi_json (1.8.4) multi_xml (0.5.5) - net-ssh (2.8.0) + net-ssh (2.9.2) nio4r (1.0.0) - posix-spawn (0.3.8) + posix-spawn (0.3.9) pry (0.9.12.6) coderay (~> 1.0) method_source (~> 0.8) diff --git a/test/integration_test.rb b/test/integration_test.rb index bc1dfa6..04561a7 100644 --- a/test/integration_test.rb +++ b/test/integration_test.rb @@ -4,22 +4,17 @@ require 'shoulda' class IntegrationTest < Test::Unit::TestCase - - def stop! - system "export INTEGRATION_TEST=true; bin/testbot --server stop > /dev/null" - system "export INTEGRATION_TEST=true; bin/testbot --runner stop > /dev/null" - end - # This is slow, and Test:Unit does not have "before/after :all" method, so I'm using a single testcase for multiple tests should "be able to send a build request, have it run and show the results" do Thread.new { sleep 30 puts "Still running after 30 secs, stopping..." - stop! + stop } - system "rm -rf tmp; mkdir -p tmp; cp -rf test/fixtures/local tmp/local" + cleanup + system "mkdir -p tmp/fixtures; cp -rf test/fixtures/local tmp/local" system "export INTEGRATION_TEST=true; bin/testbot --runner --connect 127.0.0.1 --working_dir tmp/runner > /dev/null" system "export INTEGRATION_TEST=true; bin/testbot --server > /dev/null" @@ -33,12 +28,12 @@ def stop! sleep 2.0 result = `cd tmp/local; INTEGRATION_TEST=true ../../bin/testbot --spec --connect 127.0.0.1 --rsync_path ../server --rsync_ignores "log/* tmp/*"` - + # Should include the result from script/spec #puts result.inspect assert result.include?('script/spec got called with ["-O", "spec/spec.opts", "spec/models/house_spec.rb", "spec/models/car_spec.rb"]') || - result.include?('script/spec got called with ["-O", "spec/spec.opts", "spec/models/car_spec.rb", "spec/models/house_spec.rb"]') - + result.include?('script/spec got called with ["-O", "spec/spec.opts", "spec/models/car_spec.rb", "spec/models/house_spec.rb"]') + # Should not include ignored files assert !File.exists?("tmp/server/log/test.log") @@ -46,10 +41,18 @@ def stop! assert !File.exists?("tmp/runner/local/log/test.log") assert !File.exists?("tmp/runner/local/tmp/restart.txt") end - + def teardown - stop! - FileUtils.rm_rf "tmp" + stop + cleanup + end + + def stop + system "export INTEGRATION_TEST=true; bin/testbot --server stop > /dev/null" + system "export INTEGRATION_TEST=true; bin/testbot --runner stop > /dev/null" end + def cleanup + system "rm -rf tmp/local tmp/fixtures" + end end From 81acfee50f16dc50af8f3547117b18707c7366f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Kolsj=C3=B6?= Date: Fri, 21 Mar 2014 16:55:31 +0100 Subject: [PATCH 2/6] Cleanup --- lib/requester/requester.rb | 5 +++-- test/requester/requester_test.rb | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/requester/requester.rb b/lib/requester/requester.rb index ee0e5f3..e2f0f68 100644 --- a/lib/requester/requester.rb +++ b/lib/requester/requester.rb @@ -43,8 +43,9 @@ def run_tests(adapter, dir) log "Syncing files" do rsync_ignores = config.rsync_ignores.to_s.split.map { |pattern| "--exclude='#{pattern}'" }.join(' ') - rsync_result = system("rsync -az --delete --delete-excluded -e ssh #{rsync_ignores} . #{rsync_uri}") - raise "rsync failed with exit code #{rsync_result}" unless $?.exitstatus == 0 + system("rsync -az --delete --delete-excluded -e ssh #{rsync_ignores} . #{rsync_uri}") + exitstatus = $?.exitstatus + raise "rsync failed with exit code #{exitstatus}" unless exitstatus == 0 end files = adapter.test_files(dir) diff --git a/test/requester/requester_test.rb b/test/requester/requester_test.rb index 707d342..2323cba 100644 --- a/test/requester/requester_test.rb +++ b/test/requester/requester_test.rb @@ -82,7 +82,7 @@ def fixture_path(local_path) :server_user => Testbot::DEFAULT_USER, :available_runner_usage => Testbot::DEFAULT_RUNNER_USAGE } - actual = Requester.new({ "server_host" => 'hostname' }).config + actual = Requester.new({ "server_host" => 'hostname' }).config assert_equal OpenStruct.new(expected), actual end From 6d671e615efb2c2feacb716729ade470624c76a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Kolsj=C3=B6?= Date: Fri, 21 Mar 2014 17:00:45 +0100 Subject: [PATCH 3/6] Changing to exit, makes more sense for a command line program. --- CHANGELOG | 9 +++------ README.markdown | 2 +- lib/requester/requester.rb | 3 ++- lib/shared/version.rb | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 4467581..f9ac7bf 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,10 +1,7 @@ +0.7.7 -0.7.6 - -Raise an error when file syncing fails. - -We don't want to continue when it fails. It would run the tests with an older version, -possibly enabling a broken version of the app to be deployed. +Exit when file syncing fails so that you don't run tests for a version of the +code you did not expect. 0.7.5 diff --git a/README.markdown b/README.markdown index 940398b..6f43d33 100644 --- a/README.markdown +++ b/README.markdown @@ -67,7 +67,7 @@ Using testbot with Rails 2: # Add testbot to your Gemfile if you use bundler. You also need the plugin because # Rails 2 does not load raketasks from gems. - ruby script/plugin install git://github.com/joakimk/testbot.git -r 'refs/tags/v0.7.1' + ruby script/plugin install git://github.com/joakimk/testbot.git -r 'refs/tags/v0.7.7' script/generate testbot --connect 192.168.0.100 rake testbot:spec (or :rspec, :test, :features) diff --git a/lib/requester/requester.rb b/lib/requester/requester.rb index e2f0f68..a8429a1 100644 --- a/lib/requester/requester.rb +++ b/lib/requester/requester.rb @@ -45,7 +45,8 @@ def run_tests(adapter, dir) rsync_ignores = config.rsync_ignores.to_s.split.map { |pattern| "--exclude='#{pattern}'" }.join(' ') system("rsync -az --delete --delete-excluded -e ssh #{rsync_ignores} . #{rsync_uri}") exitstatus = $?.exitstatus - raise "rsync failed with exit code #{exitstatus}" unless exitstatus == 0 + puts "rsync failed with exit code #{exitstatus}" unless exitstatus == 0 + exit 1 end files = adapter.test_files(dir) diff --git a/lib/shared/version.rb b/lib/shared/version.rb index 548db81..44dc9ef 100644 --- a/lib/shared/version.rb +++ b/lib/shared/version.rb @@ -1,7 +1,7 @@ module Testbot # Don't forget to update readme and changelog def self.version - version = "0.7.6" + version = "0.7.7" dev_version_file = File.join(File.dirname(__FILE__), '..', '..', 'DEV_VERSION') if File.exists?(dev_version_file) version += File.read(dev_version_file) From 300f87531930684c7db9581a0211fe7bde221944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Kolsj=C3=B6?= Date: Fri, 21 Mar 2014 17:02:02 +0100 Subject: [PATCH 4/6] And make it work too :) --- Gemfile.lock | 2 +- lib/requester/requester.rb | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index bb7c9a8..b433bd4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - testbot (0.7.6) + testbot (0.7.7) acts_as_rails3_generator daemons (>= 1.0.10) httparty (>= 0.6.1) diff --git a/lib/requester/requester.rb b/lib/requester/requester.rb index a8429a1..9b50654 100644 --- a/lib/requester/requester.rb +++ b/lib/requester/requester.rb @@ -44,9 +44,12 @@ def run_tests(adapter, dir) log "Syncing files" do rsync_ignores = config.rsync_ignores.to_s.split.map { |pattern| "--exclude='#{pattern}'" }.join(' ') system("rsync -az --delete --delete-excluded -e ssh #{rsync_ignores} . #{rsync_uri}") + exitstatus = $?.exitstatus - puts "rsync failed with exit code #{exitstatus}" unless exitstatus == 0 - exit 1 + unless exitstatus == 0 + puts "rsync failed with exit code #{exitstatus}" + exit 1 + end end files = adapter.test_files(dir) From bc7569a75f9c64c721d40ea40485120f2a072f67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Kolsj=C3=B6?= Date: Tue, 15 Apr 2014 17:48:41 +0200 Subject: [PATCH 5/6] Fix bug with bad instance numbers. --- CHANGELOG | 8 ++++++++ README.markdown | 2 +- lib/runner/runner.rb | 9 +++++++-- lib/shared/version.rb | 2 +- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index f9ac7bf..b38d813 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,11 @@ +0.7.8 + +Fix test job bug that caused multiple jobs to use the same TEST_ENV_NUMBER. + +This caused multiple processes to use the same databases, etc. + +If you're seeing database deadlocks in tests, this will probably fix that. + 0.7.7 Exit when file syncing fails so that you don't run tests for a version of the diff --git a/README.markdown b/README.markdown index 6f43d33..82eb684 100644 --- a/README.markdown +++ b/README.markdown @@ -67,7 +67,7 @@ Using testbot with Rails 2: # Add testbot to your Gemfile if you use bundler. You also need the plugin because # Rails 2 does not load raketasks from gems. - ruby script/plugin install git://github.com/joakimk/testbot.git -r 'refs/tags/v0.7.7' + ruby script/plugin install git://github.com/joakimk/testbot.git -r 'refs/tags/v0.7.8' script/generate testbot --connect 192.168.0.100 rake testbot:spec (or :rspec, :test, :features) diff --git a/lib/runner/runner.rb b/lib/runner/runner.rb index c6e8d4d..c937538 100644 --- a/lib/runner/runner.rb +++ b/lib/runner/runner.rb @@ -108,8 +108,13 @@ def wait_for_jobs end @last_build_id = job.build_id - @instances << [ Thread.new { job.run(free_instance_number) }, - free_instance_number, job ] + + # Must be outside the thread or it will sometimes run + # multiple jobs using the same instance number. + instance_number = free_instance_number + + @instances << [ Thread.new { job.run(instance_number) }, instance_number, job ] + loop do clear_completed_instances break unless max_instances_running? diff --git a/lib/shared/version.rb b/lib/shared/version.rb index 44dc9ef..ce6b73b 100644 --- a/lib/shared/version.rb +++ b/lib/shared/version.rb @@ -1,7 +1,7 @@ module Testbot # Don't forget to update readme and changelog def self.version - version = "0.7.7" + version = "0.7.8" dev_version_file = File.join(File.dirname(__FILE__), '..', '..', 'DEV_VERSION') if File.exists?(dev_version_file) version += File.read(dev_version_file) From 93113e81ae53c2ed78f06c302e6d04e527fa836c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Kolsj=C3=B6?= Date: Tue, 15 Apr 2014 17:54:02 +0200 Subject: [PATCH 6/6] Update version in Gemfile.lock --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index b433bd4..228dc08 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - testbot (0.7.7) + testbot (0.7.8) acts_as_rails3_generator daemons (>= 1.0.10) httparty (>= 0.6.1)