From a7aeb766aa7e05f878ed4a61775ad9a92735a630 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Fri, 19 Nov 2021 14:17:20 -0500 Subject: [PATCH] RunCommandLogs: add a helper for if it failed with an exec error --- src/lib/Hydra/Schema/Result/RunCommandLogs.pm | 22 +++++++++++++++++++ t/Schema/Result/RunCommandLogs.t | 6 +++++ t/plugins/RunCommand/errno.t | 1 + 3 files changed, 29 insertions(+) diff --git a/src/lib/Hydra/Schema/Result/RunCommandLogs.pm b/src/lib/Hydra/Schema/Result/RunCommandLogs.pm index 54e1ac1d..b74416e8 100644 --- a/src/lib/Hydra/Schema/Result/RunCommandLogs.pm +++ b/src/lib/Hydra/Schema/Result/RunCommandLogs.pm @@ -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; diff --git a/t/Schema/Result/RunCommandLogs.t b/t/Schema/Result/RunCommandLogs.t index 4953278f..69310ddd 100644 --- a/t/Schema/Result/RunCommandLogs.t +++ b/t/Schema/Result/RunCommandLogs.t @@ -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"); diff --git a/t/plugins/RunCommand/errno.t b/t/plugins/RunCommand/errno.t index 6cf6b9ea..9e06f9bb 100644 --- a/t/plugins/RunCommand/errno.t +++ b/t/plugins/RunCommand/errno.t @@ -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.");