Permalink
Browse files

added and started using childprocess (we are now a little more multi-…

…platform & have slightly cleaner code)
  • Loading branch information...
1 parent 4c2567a commit e9afb4a5f48ce805203f3108c080c6d8b15bf861 @srushti srushti committed May 23, 2011
Showing with 13 additions and 14 deletions.
  1. +1 −0 Gemfile
  2. +1 −1 app/models/build.rb
  3. +7 −5 app/models/command.rb
  4. +4 −8 spec/models/build_spec.rb
View
@@ -6,6 +6,7 @@ gem 'sqlite3', '~> 1.3.3', :platforms => :ruby
gem 'haml', '~> 3.0.25'
gem 'sass', '~> 3.1.1'
gem 'commander', '~> 4.0.4'
+gem 'childprocess', '~> 0.1.9'
platform :jruby do
gem 'jdbc-sqlite3', '~> 3.6.0'
View
@@ -71,7 +71,7 @@ def execute_async(command)
command.kill
self.status = 'timeout'
else
- self.status = Command.success? ? 'passed' : 'failed'
+ self.status = command.success? ? 'passed' : 'failed'
end
save
end
View
@@ -8,18 +8,20 @@ def execute
end
def execute_async
- @pid = Process.spawn(%{/usr/bin/env bash -c "#{@cmd.gsub(/"/, '\"')}"}).tap{|pid| Rails.logger.info("The pid of the build process is #{pid}")}
+ @process = ChildProcess.build(%{/usr/bin/env bash -c "#{@cmd.gsub(/"/, '\"')}"})
+ Rails.logger.info("The pid of the build process is #{@process.pid}")
+ @process.start
end
def running?
- Process.waitpid(@pid, Process::WNOHANG).nil?
+ @process.alive?
end
def kill
- Process.kill('KILL', @pid)
+ @process.send_kill
end
- def self.success?
- ($?).success?
+ def success?
+ @process.exit_code == 0
end
end
View
@@ -109,23 +109,20 @@
Env.should_receive(:[]=).with('BUILD_ARTIFACTS', 'artefacts path')
Env.should_receive(:[]=).with('RAILS_ENV', nil)
Environment.stub!(:system)
- Command.stub!(:new).and_return(mock(:command, :running? => false, :execute_async => nil))
- Command.stub!(:success?)
+ Command.stub!(:new).and_return(mock(:command, :running? => false, :execute_async => nil, :success? => nil))
build.run
end
it "runs the build command and update the build status" do
Environment.stub!(:system)
- Command.stub!(:new).and_return(mock(:command, :running? => false, :execute_async => nil))
- Command.stub!(:success?).and_return(true)
+ Command.stub!(:new).and_return(mock(:command, :running? => false, :execute_async => nil, :success? => true))
build.run
build.status.should == "passed"
end
it "sets build status to failed if the build command fails" do
Environment.stub!(:system)
- Command.stub!(:new).and_return(mock(:command, :running? => false, :execute_async => nil))
- Command.stub!(:success?).and_return(false)
+ Command.stub!(:new).and_return(mock(:command, :running? => false, :execute_async => nil, :success? => false))
build.run
build.status.should == "failed"
end
@@ -138,8 +135,7 @@
it "should pass the environment variables to the system command" do
build.stub(:before_build)
RVM.stub(:prepare_ruby)
- Command.stub!(:new).and_return(mock(:command, :running? => false, :execute_async => nil))
- Command.stub!(:success?).and_return(true)
+ Command.stub!(:new).and_return(mock(:command, :running? => false, :execute_async => nil, :success? => true))
build.run.should be_true
end
end

0 comments on commit e9afb4a

Please sign in to comment.