Skip to content

Commit

Permalink
avoid having 'running' TSRs after worker is killed
Browse files Browse the repository at this point in the history
  • Loading branch information
comboy committed Nov 5, 2012
1 parent efb9264 commit f6e50fd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
12 changes: 9 additions & 3 deletions app/models/test_suite.rb
Expand Up @@ -28,13 +28,19 @@ class TestSuite < ActiveRecord::Base
# Run TestSuite within given ProjectInstance
def run(project_instance)
puts " running test suite #{self.name}"
tr = TestSuiteRun.create!(
begin
tr = TestSuiteRun.create!(
:state => 'running',
:commit => project_instance.head_commit,
:project_instance => project_instance,
:test_suite => self)
runner_class.run(tr)
tr.after_run #TODO: events, successful finish
runner_class.run(tr)
tr.after_run #TODO: events, successful finish
rescue SignalException, Interrupt
# worker is getting killed, we don't care about unfinished run, destroy it
tr.destroy
raise $!
end
end

# Returns given test suite runner implementation class
Expand Down
32 changes: 31 additions & 1 deletion spec/models/test_suite_spec.rb
@@ -1,5 +1,13 @@
require 'spec_helper'

module Moci
module TestRunner
class Runtime; def self.run(ts); raise ::RuntimeError; end; end
class Interrupt; def self.run(ts); raise ::Interrupt; end; end
class Blank; def self.run(ts); true; end; end
end
end

describe TestSuite do
context "runner class" do
it "should return proper runner class" do
Expand All @@ -13,7 +21,7 @@
ts.suite_type = ""
ts.runner_class.should be_nil
end

it "should return options" do
ts = Factory :test_suite, :suite_options => {"foo" => "bar"}
ts.options[:foo].should == 'bar'
Expand All @@ -25,6 +33,28 @@
ts.save
ts.reload.options["woo"].should == "hoo"
end

context "run" do
before do
@ts = create :test_suite
@pi = create :project_instance
@pi.stub(:head_commit).and_return(create :commit)
end

it "should create test suite run" do
@ts.suite_type = 'Blank'
@ts.run(@pi)
@ts.test_suite_runs.count.should == 1
end

it "should remove test suite if there was interrupt" do
lambda do
@ts.suite_type = 'Interrupt'
@ts.run(@pi)
end.should raise_error Interrupt
@ts.test_suite_runs.count.should == 0
end
end
end
end

Expand Down

0 comments on commit f6e50fd

Please sign in to comment.