2021-11-17 20:04:32 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use Setup;
|
|
|
|
|
|
|
|
my %ctx = test_init();
|
|
|
|
|
|
|
|
require Hydra::Schema;
|
|
|
|
require Hydra::Model::DB;
|
|
|
|
|
|
|
|
use Test2::V0;
|
|
|
|
|
|
|
|
my $db = Hydra::Model::DB->new;
|
|
|
|
hydra_setup($db);
|
|
|
|
|
|
|
|
my $project = $db->resultset('Projects')->create({name => "tests", displayname => "", owner => "root"});
|
|
|
|
my $jobset = createBaseJobset("basic", "basic.nix", $ctx{jobsdir});
|
|
|
|
ok(evalSucceeds($jobset), "Evaluating jobs/basic.nix should exit with return code 0");
|
|
|
|
is(nrQueuedBuildsForJobset($jobset), 3, "Evaluating jobs/basic.nix should result in 3 builds");
|
|
|
|
|
|
|
|
my ($build, @_) = queuedBuildsForJobset($jobset);
|
|
|
|
|
|
|
|
sub new_run_log {
|
|
|
|
return $db->resultset('RunCommandLogs')->create({
|
|
|
|
job_matcher => "*:*:*",
|
|
|
|
build_id => $build->get_column('id'),
|
|
|
|
command => "bogus",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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-17 20:04:32 +00:00
|
|
|
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.");
|
|
|
|
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-17 20:04:32 +00:00
|
|
|
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");
|
|
|
|
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-17 20:04:32 +00:00
|
|
|
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");
|
|
|
|
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.");
|
|
|
|
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");
|
|
|
|
is($runlog->exit_code, undef, "The exit code is undefined.");
|
|
|
|
is($runlog->signal, 15, "Signal 15 was sent.");
|
|
|
|
is($runlog->core_dumped, 1, "There was no core dump.");
|
|
|
|
};
|
|
|
|
|
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-17 20:04:32 +00:00
|
|
|
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");
|
|
|
|
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-17 20:04:32 +00:00
|
|
|
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");
|
|
|
|
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;
|