Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generic phrase to 'died' reason if there's no more information #3359

Merged
merged 1 commit into from Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/OpenQA/Worker/Job.pm
Expand Up @@ -581,6 +581,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