2021-11-17 20:04:32 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use Setup;
|
|
|
|
use Test2::V0;
|
|
|
|
|
2021-12-15 17:03:06 +00:00
|
|
|
my $ctx = test_context();
|
|
|
|
my $db = $ctx->db();
|
2021-11-17 20:04:32 +00:00
|
|
|
|
2021-12-15 17:03:06 +00:00
|
|
|
my $builds = $ctx->makeAndEvaluateJobset(
|
|
|
|
expression => "basic.nix",
|
|
|
|
);
|
2021-11-17 20:04:32 +00:00
|
|
|
|
2021-12-15 17:03:06 +00:00
|
|
|
my $build = $builds->{"empty_dir"};
|
2021-11-17 20:04:32 +00:00
|
|
|
|
|
|
|
sub new_run_log {
|
|
|
|
return $db->resultset('RunCommandLogs')->create({
|
|
|
|
job_matcher => "*:*:*",
|
|
|
|
build_id => $build->get_column('id'),
|
|
|
|
command => "bogus",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-01-24 16:56:34 +00:00
|
|
|
subtest "A new record has a UUID" => sub {
|
|
|
|
my $runlog = new_run_log();
|
|
|
|
is(length($runlog->uuid), 36, "The UUID attribute is sufficiently UUID-like.");
|
|
|
|
like($runlog->uuid, qr/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/, "The UUID attribute is sufficiently UUID-like.");
|
|
|
|
};
|
|
|
|
|
2021-11-17 20:04:32 +00:00
|
|
|
subtest "Not yet started" => sub {
|
|
|
|
my $runlog = new_run_log();
|
|
|
|
|
|
|
|
is($runlog->start_time, undef, "The start time is undefined.");
|
|
|
|
is($runlog->end_time, undef, "The start time is undefined.");
|
|
|
|
is($runlog->exit_code, undef, "The exit code is undefined.");
|
|
|
|
is($runlog->signal, undef, "The signal is undefined.");
|
|
|
|
is($runlog->core_dumped, undef, "The core dump status is undefined.");
|
|
|
|
};
|
|
|
|
|
|
|
|
subtest "Completing a process before it is started is invalid" => sub {
|
|
|
|
my $runlog = new_run_log();
|
|
|
|
|
|
|
|
like(
|
|
|
|
dies {
|
|
|
|
$runlog->completed_with_child_error(0, 0);
|
|
|
|
},
|
|
|
|
qr/runcommandlogs_end_time_has_start_time/,
|
|
|
|
"It is invalid to complete the process before it started"
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
subtest "Starting a process" => sub {
|
|
|
|
my $runlog = new_run_log();
|
|
|
|
$runlog->started();
|
2021-11-18 19:27:00 +00:00
|
|
|
is($runlog->did_succeed(), undef, "The process has not yet succeeded.");
|
2021-11-19 18:21:45 +00:00
|
|
|
ok($runlog->is_running(), "The process is running.");
|
|
|
|
ok(!$runlog->did_fail_with_signal(), "The process was not killed by a signal.");
|
2021-11-19 19:17:20 +00:00
|
|
|
ok(!$runlog->did_fail_with_exec_error(), "The process did not fail to start due to an exec error.");
|
2023-06-23 13:09:09 +00:00
|
|
|
is($runlog->start_time, within(time() - 1, 5), "The start time is recent.");
|
2021-11-17 20:04:32 +00:00
|
|
|
is($runlog->end_time, undef, "The end time is undefined.");
|
|
|
|
is($runlog->exit_code, undef, "The exit code is undefined.");
|
|
|
|
is($runlog->signal, undef, "The signal is undefined.");
|
|
|
|
is($runlog->core_dumped, undef, "The core dump status is undefined.");
|
|
|
|
};
|
|
|
|
|
|
|
|
subtest "The process completed (success)" => sub {
|
|
|
|
my $runlog = new_run_log();
|
|
|
|
$runlog->started();
|
|
|
|
$runlog->completed_with_child_error(0, 123);
|
2021-11-18 19:27:00 +00:00
|
|
|
ok($runlog->did_succeed(), "The process did succeed.");
|
2021-11-19 18:21:45 +00:00
|
|
|
ok(!$runlog->is_running(), "The process is not running.");
|
|
|
|
ok(!$runlog->did_fail_with_signal(), "The process was not killed by a signal.");
|
2021-11-19 19:17:20 +00:00
|
|
|
ok(!$runlog->did_fail_with_exec_error(), "The process did not fail to start due to an exec error.");
|
2023-06-23 13:09:09 +00:00
|
|
|
is($runlog->start_time, within(time() - 1, 5), "The start time is recent.");
|
|
|
|
is($runlog->end_time, within(time() - 1, 5), "The end time is recent.");
|
2021-11-17 20:04:32 +00:00
|
|
|
is($runlog->error_number, undef, "The error number is undefined");
|
|
|
|
is($runlog->exit_code, 0, "The exit code is 0.");
|
|
|
|
is($runlog->signal, undef, "The signal is undefined.");
|
|
|
|
is($runlog->core_dumped, undef, "The core dump is undefined.");
|
|
|
|
};
|
|
|
|
|
|
|
|
subtest "The process completed (errored)" => sub {
|
|
|
|
my $runlog = new_run_log();
|
|
|
|
$runlog->started();
|
|
|
|
$runlog->completed_with_child_error(21760, 123);
|
2021-11-18 19:27:00 +00:00
|
|
|
ok(!$runlog->did_succeed(), "The process did not succeed.");
|
2021-11-19 18:21:45 +00:00
|
|
|
ok(!$runlog->is_running(), "The process is not running.");
|
|
|
|
ok(!$runlog->did_fail_with_signal(), "The process was not killed by a signal.");
|
2021-11-19 19:17:20 +00:00
|
|
|
ok(!$runlog->did_fail_with_exec_error(), "The process did not fail to start due to an exec error.");
|
2023-06-23 13:09:09 +00:00
|
|
|
is($runlog->start_time, within(time() - 1, 5), "The start time is recent.");
|
|
|
|
is($runlog->end_time, within(time() - 1, 5), "The end time is recent.");
|
2021-11-17 20:04:32 +00:00
|
|
|
is($runlog->error_number, undef, "The error number is undefined");
|
|
|
|
is($runlog->exit_code, 85, "The exit code is 85.");
|
|
|
|
is($runlog->signal, undef, "The signal is undefined.");
|
|
|
|
is($runlog->core_dumped, undef, "The core dump is undefined.");
|
|
|
|
};
|
|
|
|
|
2021-11-19 17:29:53 +00:00
|
|
|
subtest "The process completed (status 15, child error 0)" => sub {
|
|
|
|
my $runlog = new_run_log();
|
|
|
|
$runlog->started();
|
|
|
|
$runlog->completed_with_child_error(15, 0);
|
|
|
|
ok(!$runlog->did_succeed(), "The process did not succeed.");
|
2021-11-19 18:21:45 +00:00
|
|
|
ok(!$runlog->is_running(), "The process is not running.");
|
|
|
|
ok($runlog->did_fail_with_signal(), "The process was killed by a signal.");
|
2021-11-19 19:17:20 +00:00
|
|
|
ok(!$runlog->did_fail_with_exec_error(), "The process did not fail to start due to an exec error.");
|
2023-06-23 13:09:09 +00:00
|
|
|
is($runlog->start_time, within(time() - 1, 5), "The start time is recent.");
|
|
|
|
is($runlog->end_time, within(time() - 1, 5), "The end time is recent.");
|
2021-11-19 17:29:53 +00:00
|
|
|
is($runlog->error_number, undef, "The error number is undefined");
|
|
|
|
is($runlog->exit_code, undef, "The exit code is undefined.");
|
|
|
|
is($runlog->signal, 15, "Signal 15 was sent.");
|
2021-11-19 18:21:45 +00:00
|
|
|
is($runlog->core_dumped, 0, "There was no core dump.");
|
2021-11-19 17:29:53 +00:00
|
|
|
};
|
|
|
|
|
2021-11-17 20:04:32 +00:00
|
|
|
subtest "The process completed (signaled)" => sub {
|
|
|
|
my $runlog = new_run_log();
|
|
|
|
$runlog->started();
|
|
|
|
$runlog->completed_with_child_error(393, 234);
|
2021-11-18 19:27:00 +00:00
|
|
|
ok(!$runlog->did_succeed(), "The process did not succeed.");
|
2021-11-19 18:21:45 +00:00
|
|
|
ok(!$runlog->is_running(), "The process is not running.");
|
|
|
|
ok($runlog->did_fail_with_signal(), "The process was killed by a signal.");
|
2021-11-19 19:17:20 +00:00
|
|
|
ok(!$runlog->did_fail_with_exec_error(), "The process did not fail to start due to an exec error.");
|
2023-06-23 13:09:09 +00:00
|
|
|
is($runlog->start_time, within(time() - 1, 5), "The start time is recent.");
|
|
|
|
is($runlog->end_time, within(time() - 1, 5), "The end time is recent.");
|
2021-11-17 20:04:32 +00:00
|
|
|
is($runlog->error_number, undef, "The error number is undefined");
|
|
|
|
is($runlog->exit_code, undef, "The exit code is undefined.");
|
|
|
|
is($runlog->signal, 9, "The signal is 9.");
|
|
|
|
is($runlog->core_dumped, 1, "The core dumped.");
|
|
|
|
};
|
|
|
|
|
|
|
|
subtest "The process failed to start" => sub {
|
|
|
|
my $runlog = new_run_log();
|
|
|
|
$runlog->started();
|
|
|
|
$runlog->completed_with_child_error(-1, 2);
|
2021-11-18 19:27:00 +00:00
|
|
|
ok(!$runlog->did_succeed(), "The process did not succeed.");
|
2021-11-19 18:21:45 +00:00
|
|
|
ok(!$runlog->is_running(), "The process is running.");
|
|
|
|
ok(!$runlog->did_fail_with_signal(), "The process was not killed by a signal.");
|
2021-11-19 19:17:20 +00:00
|
|
|
ok($runlog->did_fail_with_exec_error(), "The process failed to start due to an exec error.");
|
2023-06-23 13:09:09 +00:00
|
|
|
is($runlog->start_time, within(time() - 1, 5), "The start time is recent.");
|
|
|
|
is($runlog->end_time, within(time() - 1, 5), "The end time is recent.");
|
2021-11-17 20:04:32 +00:00
|
|
|
is($runlog->error_number, 2, "The error number is saved");
|
|
|
|
is($runlog->exit_code, undef, "The exit code is undefined.");
|
|
|
|
is($runlog->signal, undef, "The signal is undefined.");
|
|
|
|
is($runlog->core_dumped, undef, "The core dumped is not defined.");
|
|
|
|
};
|
|
|
|
|
|
|
|
done_testing;
|