Debian Codegraph @

t/integration/shares.t

raw
1 use Test2::V0;
2
3 use File::Spec;
4 use File::Temp qw/tempdir/;
5
6 use App::Yath::Tester qw/yath/;
7 use Test2::Harness::Util::File::JSONL;
8
9 my $dir = __FILE__;
10 $dir =~ s{\.t$}{}g;
11 $dir =~ s{^\./}{};
12
13 # HARNESS-SHARES-DB tests may run alongside each other, but never alongside a
14 # HARNESS-CONFLICTS-DB test. Read the window each test was live for out of the
15 # log and check which windows were allowed to overlap.
16 my $barrier = tempdir(CLEANUP => 1);
17
18 yath(
19 command => 'test',
20 args => [
21 $dir, '--ext=tx', '-j4',
22 '-It/lib',
23 '--env-var' => "TEST_BARRIER_DIR=$barrier",
24 '--env-var' => "TEST_BARRIER_COUNT=2",
25 ],
26 log => 1,
27 exit => 0,
28 test => sub {
29 my $out = shift;
30 my $log = $out->{log};
31
32 my (%name, %start, %stop);
33
34 my @events = $log->poll();
35 while (@events) {
36 if (my $event = shift @events) {
37 my $f = $event->{facet_data};
38 my $job_id = $event->{job_id} // next;
39
40 if (my $s = $f->{harness_job_start}) {
41 $name{$job_id} = (File::Spec->splitpath($s->{rel_file}))[-1];
42 $start{$job_id} = $s->{stamp};
43 }
44
45 if (my $e = $f->{harness_job_exit}) {
46 $stop{$job_id} = $e->{stamp};
47 }
48 }
49
50 # Check for additional events, probably should not have any, but we
51 # may hit a buffering limit in the log reader and need additional
52 # polls.
53 push @events => $log->poll;
54 }
55
56 my %window;
57 for my $job_id (keys %name) {
58 $window{$name{$job_id}} = [$start{$job_id}, $stop{$job_id}];
59 }
60
61 is([sort keys %window], [sort qw/exclusive.tx shared_a.tx shared_b.tx/], "Found all three tests in the log");
62
63 my $overlap = sub {
64 my ($x, $y) = @_;
65 my ($xa, $xb) = @{$window{$x}};
66 my ($ya, $yb) = @{$window{$y}};
67 return $xa < $yb && $ya < $xb;
68 };
69
70 ok(!$overlap->('exclusive.tx', 'shared_a.tx'), "exclusive did not run alongside shared_a");
71 ok(!$overlap->('exclusive.tx', 'shared_b.tx'), "exclusive did not run alongside shared_b");
72 ok($overlap->('shared_a.tx', 'shared_b.tx'), "the two shared tests did run alongside each other");
73 },
74 );
75
76 done_testing;