Skip to content

Commit

Permalink
Merge pull request #3359 from Martchus/died
Browse files Browse the repository at this point in the history
Add generic phrase to 'died' reason if there's no more information
  • Loading branch information
mergify[bot] committed Sep 3, 2020
2 parents 2852187 + d825180 commit 074365e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions lib/OpenQA/Worker/Job.pm
Expand Up @@ -582,6 +582,9 @@ sub _format_reason {
log_warning("Found $state_file but failed to parse the JSON: $_");
};

# return generic phrase if the reason would otherwise just be died
return "$reason: terminated prematurely, see log output for details" if $reason eq WORKER_SR_DIED;

# discard the reason if it is just WORKER_SR_DONE or the same as the result; otherwise return it
return undef unless $reason ne WORKER_SR_DONE && (!defined $result || $result ne $reason);
return $reason;
Expand Down
11 changes: 6 additions & 5 deletions t/24-worker-jobs.t
Expand Up @@ -28,7 +28,7 @@ use Mojo::JSON 'encode_json';
use Mojo::UserAgent;
use Mojo::URL;
use Mojo::IOLoop;
use OpenQA::Constants qw(DEFAULT_MAX_JOB_TIME WORKER_COMMAND_QUIT WORKER_SR_SETUP_FAILURE
use OpenQA::Constants qw(DEFAULT_MAX_JOB_TIME WORKER_COMMAND_CANCEL WORKER_COMMAND_QUIT WORKER_SR_SETUP_FAILURE
WORKER_SR_API_FAILURE WORKER_SR_DIED WORKER_SR_DONE);
use OpenQA::Worker::Job;
use OpenQA::Worker::Settings;
Expand Down Expand Up @@ -222,10 +222,11 @@ subtest 'Format reason' => sub {
# call the function explicitely; further cases are covered in subsequent subtests where the
# function is called indirectly
my $job = OpenQA::Worker::Job->new($worker, $client, {id => 1234});
is($job->_format_reason(PASSED, 'done'), undef, 'no reason added if it is just "done"');
is($job->_format_reason('foo', 'foo'), undef, 'no reason added if it equals the result');
is($job->_format_reason('foo', 'foobar'), 'foobar', 'unknown reason "passed as-is" if it differs from the result');
is($job->_format_reason(USER_CANCELLED, 'cancel'), undef, 'cancel omitted');
is($job->_format_reason(PASSED, WORKER_SR_DONE), undef, 'no reason added if it is just "done"');
like($job->_format_reason(INCOMPLETE, WORKER_SR_DIED), qr/died: .+/, 'generic phrase appended to died');
is($job->_format_reason('foo', 'foo'), undef, 'no reason added if it equals the result');
is($job->_format_reason('foo', 'foobar'), 'foobar', 'unknown reason "passed as-is" if it differs from the result');
is($job->_format_reason(USER_CANCELLED, WORKER_COMMAND_CANCEL), undef, 'cancel omitted');
};

subtest 'Interrupted WebSocket connection' => sub {
Expand Down

0 comments on commit 074365e

Please sign in to comment.