Debian Codegraph @

t/integration/scheduler_death.t

raw
1 use Test2::V0;
2
3 use App::Yath::Tester qw/yath/;
4
5 my $dir = __FILE__;
6 $dir =~ s{\.t$}{}g;
7 $dir =~ s{^\./}{};
8
9 # Test 1: Scheduler crashes (repeated non-zero exit)
10 # SchedulerKillerResource dies in tick() on every iteration after the first
11 # task is dispatched. The scheduler retries up to 5 times, then aborts.
12 # The parent runner detects the non-zero exit.
13 yath(
14 command => 'test',
15 args => [$dir, '--ext=tx', '-j2', "-D$dir", '-R+SchedulerKillerResource'],
16 env => {SCHEDULER_DEATH_MODE => 'crash'},
17 exit => T(),
18 test => sub {
19 my $out = shift;
20 like($out->{output}, qr/Scheduler error.*Intentional scheduler crash/, "Scheduler printed error on crash");
21 like($out->{output}, qr/Scheduler aborting after .* consecutive errors/, "Scheduler aborted after reaching error limit");
22 like($out->{output}, qr/Scheduler process.*exited unexpectedly/, "Runner detected scheduler crash");
23 },
24 );
25
26 # Test 2: Scheduler exits 0 prematurely (with pending work)
27 # SchedulerKillerResource calls POSIX::_exit(0) after the first task is
28 # dispatched, bypassing all Perl cleanup. The parent runner detects that
29 # the scheduler exited cleanly but work remains.
30 yath(
31 command => 'test',
32 args => [$dir, '--ext=tx', '-j2', "-D$dir", '-R+SchedulerKillerResource'],
33 env => {SCHEDULER_DEATH_MODE => 'exit'},
34 exit => T(),
35 test => sub {
36 my $out = shift;
37 like($out->{output}, qr/Scheduler process.*exited prematurely.*pending work/, "Runner detected premature scheduler exit");
38 },
39 );
40
41 # Test 3: Scheduler recovers from transient errors
42 # SchedulerKillerResource throws 2 times then stops. The scheduler catches
43 # the errors, retries, and successfully completes the test run.
44 yath(
45 command => 'test',
46 args => [$dir, '--ext=tx', '-j2', "-D$dir", '-R+SchedulerKillerResource'],
47 env => {SCHEDULER_DEATH_MODE => 'recover'},
48 exit => 0,
49 test => sub {
50 my $out = shift;
51 like($out->{output}, qr/Scheduler error.*Transient scheduler error/, "Scheduler logged transient error");
52 unlike($out->{output}, qr/Scheduler aborting/, "Scheduler did not abort");
53 },
54 );
55
56 done_testing;