RunCommandLogs: add a helper for if it failed with an exec error

This commit is contained in:
Graham Christensen 2021-11-19 14:17:20 -05:00
parent d849856dcd
commit a7aeb766aa
3 changed files with 29 additions and 0 deletions

View file

@ -297,5 +297,27 @@ sub did_fail_with_signal {
return defined($self->signal);
}
=head2 did_fail_with_exec_error
Looks in the database to see if the task failed with a signal.
Return:
* true if the task is not running and failed with a signal.
* false if the task is running or exited with an exit code.
=cut
sub did_fail_with_exec_error {
my ($self) = @_;
if ($self->is_running()) {
return 0;
}
if ($self->did_succeed()) {
return 0;
}
return defined($self->error_number);
}
1;

View file

@ -56,6 +56,7 @@ subtest "Starting a process" => sub {
is($runlog->did_succeed(), undef, "The process has not yet succeeded.");
ok($runlog->is_running(), "The process is running.");
ok(!$runlog->did_fail_with_signal(), "The process was not killed by a signal.");
ok(!$runlog->did_fail_with_exec_error(), "The process did not fail to start due to an exec error.");
is($runlog->start_time, within(time() - 1, 2), "The start time is recent.");
is($runlog->end_time, undef, "The end time is undefined.");
is($runlog->exit_code, undef, "The exit code is undefined.");
@ -70,6 +71,7 @@ subtest "The process completed (success)" => sub {
ok($runlog->did_succeed(), "The process did succeed.");
ok(!$runlog->is_running(), "The process is not running.");
ok(!$runlog->did_fail_with_signal(), "The process was not killed by a signal.");
ok(!$runlog->did_fail_with_exec_error(), "The process did not fail to start due to an exec error.");
is($runlog->start_time, within(time() - 1, 2), "The start time is recent.");
is($runlog->end_time, within(time() - 1, 2), "The end time is recent.");
is($runlog->error_number, undef, "The error number is undefined");
@ -85,6 +87,7 @@ subtest "The process completed (errored)" => sub {
ok(!$runlog->did_succeed(), "The process did not succeed.");
ok(!$runlog->is_running(), "The process is not running.");
ok(!$runlog->did_fail_with_signal(), "The process was not killed by a signal.");
ok(!$runlog->did_fail_with_exec_error(), "The process did not fail to start due to an exec error.");
is($runlog->start_time, within(time() - 1, 2), "The start time is recent.");
is($runlog->end_time, within(time() - 1, 2), "The end time is recent.");
is($runlog->error_number, undef, "The error number is undefined");
@ -100,6 +103,7 @@ subtest "The process completed (status 15, child error 0)" => sub {
ok(!$runlog->did_succeed(), "The process did not succeed.");
ok(!$runlog->is_running(), "The process is not running.");
ok($runlog->did_fail_with_signal(), "The process was killed by a signal.");
ok(!$runlog->did_fail_with_exec_error(), "The process did not fail to start due to an exec error.");
is($runlog->start_time, within(time() - 1, 2), "The start time is recent.");
is($runlog->end_time, within(time() - 1, 2), "The end time is recent.");
is($runlog->error_number, undef, "The error number is undefined");
@ -115,6 +119,7 @@ subtest "The process completed (signaled)" => sub {
ok(!$runlog->did_succeed(), "The process did not succeed.");
ok(!$runlog->is_running(), "The process is not running.");
ok($runlog->did_fail_with_signal(), "The process was killed by a signal.");
ok(!$runlog->did_fail_with_exec_error(), "The process did not fail to start due to an exec error.");
is($runlog->start_time, within(time() - 1, 2), "The start time is recent.");
is($runlog->end_time, within(time() - 1, 2), "The end time is recent.");
is($runlog->error_number, undef, "The error number is undefined");
@ -130,6 +135,7 @@ subtest "The process failed to start" => sub {
ok(!$runlog->did_succeed(), "The process did not succeed.");
ok(!$runlog->is_running(), "The process is running.");
ok(!$runlog->did_fail_with_signal(), "The process was not killed by a signal.");
ok($runlog->did_fail_with_exec_error(), "The process failed to start due to an exec error.");
is($runlog->start_time, within(time() - 1, 2), "The start time is recent.");
is($runlog->end_time, within(time() - 1, 2), "The end time is recent.");
is($runlog->error_number, 2, "The error number is saved");

View file

@ -40,6 +40,7 @@ ok(sendNotifications(), "Notifications execute successfully.");
subtest "Validate a run log was created" => sub {
my $runlog = $build->runcommandlogs->find({});
ok(!$runlog->did_succeed(), "The process did not succeed.");
ok($runlog->did_fail_with_exec_error(), "The process failed to start due to an exec error.");
is($runlog->job_matcher, "*:*:*", "An unspecified job matcher is defaulted to *:*:*");
is($runlog->command, 'invalid-command-this-does-not-exist', "The executed command is saved.");
is($runlog->start_time, within(time() - 1, 2), "The start time is recent.");