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

Commit

Permalink
Merge branch 'issue_75_return_code_zero_on_originator_crash'
Browse files Browse the repository at this point in the history
  • Loading branch information
Fitzsimmons committed Aug 26, 2016
2 parents 37bfdcf + 64314da commit cb4ec13
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/gorgon/originator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ def originate
publish
@logger.log "Originator finished successfully"
rescue StandardError
puts "Unhandled exception in originator:"
puts $!.message
puts $!.backtrace.join("\n")
puts "----------------------------------"
puts "Now attempting to cancel the job."
$stderr.puts "Unhandled exception in originator:"
$stderr.puts $!.message
$stderr.puts $!.backtrace.join("\n")
$stderr.puts "----------------------------------"
$stderr.puts "Now attempting to cancel the job."
@logger.log_error "Unhandled Exception!" if @logger
cancel_job
exit 2
end
end

Expand Down
17 changes: 17 additions & 0 deletions spec/originator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@
end
end

describe "#originate" do
before do
stub_methods
end

it "exits with a non-zero status code when the originator crashes" do
originator_logger.stub(:log_error)
$stderr = StringIO.new # slurp up the error output so we don't pollute the rsync run
CallbackHandler.any_instance.should_receive(:before_originate).and_throw("I'm an unhandled exception")

expect { @originator.originate }.to raise_error(SystemExit) do |error|
error.success?.should be_false
end
$stderr = STDERR
end
end

describe "#cancel_job" do
before do
stub_methods
Expand Down

0 comments on commit cb4ec13

Please sign in to comment.