Skip to content
This repository has been archived by the owner on Sep 16, 2020. It is now read-only.

Commit

Permalink
Don't stop the runner when job result update fails to post.
Browse files Browse the repository at this point in the history
  • Loading branch information
joakimk committed Jun 4, 2013
1 parent 4dc422b commit b73c0b9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
testbot (0.7.1)
testbot (0.7.2)
acts_as_rails3_generator
daemons (>= 1.0.10)
httparty (>= 0.6.1)
Expand Down
4 changes: 3 additions & 1 deletion lib/runner/job.rb
Expand Up @@ -58,11 +58,13 @@ def measure_run_time

def post_results(output)
Server.put("/jobs/#{@id}", :body => { :result => SafeResultText.clean(output), :status => "building" })
rescue Timeout::Error
puts "Got a timeout when posting an job result update. This can happen when the server is busy and is not a critical error."
end

def run_and_return_result(command)
read_pipe = spawn_process(command)

output = ""
last_post_time = Time.now
while char = read_pipe.getc
Expand Down
26 changes: 23 additions & 3 deletions test/runner/job_test.rb
Expand Up @@ -15,8 +15,16 @@ def expect_put_with(id, result_text, status, time = 0)
{ :result => expected_result, :status => status, :time => time })
end

def expect_put
flexmock(Server).should_receive(:put).once
end

def expect_put_to_timeout
flexmock(Server).should_receive(:put).and_raise(Timeout::Error)
end

def stub_duration(seconds)
time ||= Time.now
time ||= Time.now
flexmock(Time).should_receive(:now).and_return(time, time + seconds)
end

Expand All @@ -34,7 +42,19 @@ def stub_duration(seconds)
job.run(0)
end

should "return false on success if the job fails" do
should "not raise an error when posting results time out" do
job = Job.new(Runner.new({}), 10, "00:00", "project", "/tmp/testbot/user", "spec", "ruby", "spec/foo_spec.rb spec/bar_spec.rb")
flexmock(job).should_receive(:puts)

# We're using send here because triggering post_results though the rest of the
# code requires very complex setup. The code need to be refactored to be more testable.
expect_put
job.send(:post_results, "result text")
expect_put_to_timeout
job.send(:post_results, "result text")
end

should "not be successful when the job fails" do
job = Job.new(Runner.new({}), 10, "00:00", "project", "/tmp/testbot/user", "spec", "ruby", "spec/foo_spec.rb spec/bar_spec.rb")
flexmock(job).should_receive(:puts)
stub_duration(0)
Expand Down Expand Up @@ -62,7 +82,7 @@ def stub_duration(seconds)
job = Job.new(Runner.new({}), 10, "00:00", "project", "/tmp/testbot/user", "spec", "ruby", "spec/foo_spec.rb spec/bar_spec.rb")
flexmock(job).should_receive(:puts)

stub_duration(10.55)
stub_duration(10.55)
expect_put_with(10, "result text", "successful", 1055)
flexmock(job).should_receive(:run_and_return_result).and_return('result text')
flexmock(RubyEnv).should_receive(:rvm?).returns(false)
Expand Down

0 comments on commit b73c0b9

Please sign in to comment.