Permalink
Browse files

Updating and adapting new process code to the latest master. Using th…

…e posix-spawn gem to get the same process API for ruby 1.8.7.
  • Loading branch information...
1 parent 9bcf375 commit e17202b43abfde4e18c13ffa4d699465b565ab0e @joakimk committed Apr 29, 2012
View
@@ -1,35 +1,37 @@
PATH
remote: .
specs:
- testbot (0.6.3)
+ testbot (0.6.5)
acts_as_rails3_generator
daemons (>= 1.0.10)
httparty (>= 0.6.1)
json_pure (>= 1.4.6)
macaddr (>= 1.0.0)
net-ssh (>= 2.0.23)
+ posix-spawn (>= 0.3.6)
sinatra (>= 1.0.0)
GEM
remote: http://rubygems.org/
specs:
acts_as_rails3_generator (0.0.1)
- daemons (1.1.6)
+ daemons (1.1.8)
flexmock (0.8.11)
guard (0.4.2)
thor (~> 0.14.6)
guard-test (0.3.0)
guard (>= 0.2.2)
test-unit (~> 2.2)
- httparty (0.8.1)
- multi_json
+ httparty (0.8.3)
+ multi_json (~> 1.0)
multi_xml
- json_pure (1.6.5)
+ json_pure (1.7.0)
macaddr (1.5.0)
systemu (>= 2.4.0)
- multi_json (1.0.4)
- multi_xml (0.4.1)
+ multi_json (1.3.4)
+ multi_xml (0.4.4)
net-ssh (2.3.0)
+ posix-spawn (0.3.6)
rack (1.2.1)
rack-test (0.5.6)
rack (>= 1.0)
@@ -39,7 +41,7 @@ GEM
sinatra (1.2.8)
rack (~> 1.1)
tilt (>= 1.2.2, < 2.0)
- systemu (2.4.2)
+ systemu (2.5.0)
test-unit (2.3.0)
thor (0.14.6)
tilt (1.3.3)
View
@@ -1,5 +1,6 @@
require File.expand_path(File.join(File.dirname(__FILE__), 'runner.rb'))
require File.expand_path(File.join(File.dirname(__FILE__), 'safe_result_text.rb'))
+require 'posix/spawn'
module Testbot::Runner
class Job
@@ -59,9 +60,7 @@ def post_results(output)
end
def run_and_return_result(command)
- read_pipe, write_pipe = IO.pipe
- @pid = spawn(command, err: write_pipe, out: write_pipe, pgroup: true)
- output = read_pipe.read
+ read_pipe = spawn_process(command)
output = ""
last_post_time = Time.now
@@ -73,14 +72,25 @@ def run_and_return_result(command)
last_post_time = Time.now
end
end
- write_pipe.close
# Kill child processes, if any
kill_processes
output
end
+ def spawn_process(command)
+ read_pipe, write_pipe = IO.pipe
+ @pid = POSIX::Spawn::spawn(command, :err => write_pipe, :out => write_pipe, :pgroup => true)
+
+ Thread.new do
+ Process.wait(@pid)
+ write_pipe.close
+ end
+
+ read_pipe
+ end
+
def success?
$?.exitstatus == 0
end
View
@@ -127,10 +127,14 @@ def fetch_code(job)
end
def before_run(job)
- bundler_cmd = RubyEnv.bundler?(job.project) && system("cd #{job.project}; bundle") ? "bundle exec " : ""
+ using_bundler = RubyEnv.bundler?(job.project)
+ bundler_cmd = using_bundler ? "bundle exec" : ""
command_prefix = "cd #{job.project}; RAILS_ENV=test TEST_INSTANCES=#{@config.max_instances} #{bundler_cmd}"
- system "#{command_prefix}rake testbot:before_run" if File.exists?("#{job.project}/lib/tasks/testbot.rake")
- system "#{command_prefix}ruby config/testbot/before_run.rb" if File.exists?("#{job.project}/config/testbot/before_run.rb")
+
+ # todo: exit if this fails, report back, etc.
+ system("cd #{job.project}; bundle") if using_bundler
+ system "#{command_prefix} rake testbot:before_run" if File.exists?("#{job.project}/lib/tasks/testbot.rake")
+ system "#{command_prefix} ruby config/testbot/before_run.rb" if File.exists?("#{job.project}/config/testbot/before_run.rb")
end
def first_job_from_build?
@@ -233,7 +233,7 @@ def fixture_path(local_path)
flexmock(HTTParty).should_receive(:get).once.with("http://192.168.1.100:#{Testbot::SERVER_PORT}/builds/5",
:format => :json).and_return({ "done" => true, "results" => "" })
- flexmock(requester).should_receive('system').with("rsync -az --delete -e ssh --exclude='.git' --exclude='tmp' . testbot@192.168.1.100:/path")
+ flexmock(requester).should_receive('system').with("rsync -az --delete --delete-excluded -e ssh --exclude='.git' --exclude='tmp' . testbot@192.168.1.100:/path")
mock_file_sizes
requester.run_tests(RspecAdapter, 'spec')
@@ -336,7 +336,7 @@ def fixture_path(local_path)
flexmock(requester).should_receive(:print)
flexmock(requester).should_receive(:puts)
- flexmock(requester).should_receive('system').with("rsync -az --delete -e ssh . cruise@somewhere:/tmp/testbot/foo")
+ flexmock(requester).should_receive('system').with("rsync -az --delete --delete-excluded -e ssh . cruise@somewhere:/tmp/testbot/foo")
mock_file_sizes
requester.run_tests(RspecAdapter, 'spec')
View
@@ -12,10 +12,38 @@ class RunnerTest < Test::Unit::TestCase
flexmock(RubyEnv).should_receive(:bundler?).with("/path").returns(true)
runner = Runner.new({:max_instances => 1})
+ flexmock(File).should_receive(:exists?).with("/path/lib/tasks/testbot.rake").and_return(true)
+ flexmock(File).should_receive(:exists?).with("/path/config/testbot/before_run.rb").and_return(false)
flexmock(runner)
- flexmock(runner).should_receive(:system).with("export RAILS_ENV=test; export TEST_INSTANCES=1; cd /path; bundle; bundle exec rake testbot:before_run").once
+ flexmock(runner).should_receive(:system).with("cd /path; bundle").once
+ flexmock(runner).should_receive(:system).with("cd /path; RAILS_ENV=test TEST_INSTANCES=1 bundle exec rake testbot:before_run").once
runner.send(:before_run, job)
end
+
+ should "be able to use a plain ruby before_run file" do
+ job = flexmock(:job, :project => "/path")
+ flexmock(RubyEnv).should_receive(:bundler?).with("/path").returns(true)
+
+ runner = Runner.new({:max_instances => 1})
+ flexmock(File).should_receive(:exists?).with("/path/lib/tasks/testbot.rake").and_return(false)
+ flexmock(File).should_receive(:exists?).with("/path/config/testbot/before_run.rb").and_return(true)
+ flexmock(runner)
+ flexmock(runner).should_receive(:system).with("cd /path; bundle").once
+ flexmock(runner).should_receive(:system).with("cd /path; RAILS_ENV=test TEST_INSTANCES=1 bundle exec ruby config/testbot/before_run.rb").once
+ runner.send(:before_run, job)
+ end
+
+ should "be able to run without bundler" do
+ job = flexmock(:job, :project => "/path")
+ flexmock(RubyEnv).should_receive(:bundler?).with("/path").returns(false)
+
+ runner = Runner.new({:max_instances => 1})
+ flexmock(File).should_receive(:exists?).with("/path/lib/tasks/testbot.rake").and_return(false)
+ flexmock(File).should_receive(:exists?).with("/path/config/testbot/before_run.rb").and_return(true)
+ flexmock(runner)
+ flexmock(runner).should_receive(:system).with("cd /path; RAILS_ENV=test TEST_INSTANCES=1 ruby config/testbot/before_run.rb").once
+ runner.send(:before_run, job)
+ end
end
end
@@ -8,19 +8,19 @@ class RubyEnvTest < Test::Unit::TestCase
context "self.bundler?" do
should "return true if bundler is installed and there is a Gemfile" do
- flexmock(Gem).should_receive(:available?).with("bundler").once.and_return(true)
+ flexmock(Gem::Specification).should_receive(:find_by_name).with("bundler").once.and_return(true)
flexmock(File).should_receive(:exists?).with("path/to/project/Gemfile").once.and_return(true)
assert_equal true, RubyEnv.bundler?("path/to/project")
end
should "return false if bundler is installed but there is no Gemfile" do
- flexmock(Gem).should_receive(:available?).with("bundler").once.and_return(true)
+ flexmock(Gem::Specification).should_receive(:find_by_name).with("bundler").once.and_return(true)
flexmock(File).should_receive(:exists?).and_return(false)
assert_equal false, RubyEnv.bundler?("path/to/project")
end
should "return false if bundler is not installed" do
- flexmock(Gem).should_receive(:available?).with("bundler").once.and_return(false)
+ flexmock(Gem::Specification).should_receive(:find_by_name).with("bundler").once.and_return(false)
assert_equal false, RubyEnv.bundler?("path/to/project")
end
@@ -53,7 +53,6 @@ class RubyEnvTest < Test::Unit::TestCase
end
should "not look for a script when none is provided" do
- flexmock(File).should_receive(:exists?).once # Once for bundler check
assert_equal 'ruby -S rspec', RubyEnv.ruby_command("path/to/project", :bin => "rspec")
end
View
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
s.add_dependency('json_pure', '>= 1.4.6')
s.add_dependency('daemons', '>= 1.0.10')
s.add_dependency('acts_as_rails3_generator')
+ s.add_dependency('posix-spawn', '>= 0.3.6')
s.add_development_dependency("shoulda")
s.add_development_dependency("rack-test")

0 comments on commit e17202b

Please sign in to comment.