| 1 |
use Test2::V0; |
| 2 |
# HARNESS-DURATION-LONG |
| 3 |
use Test2::Require::AuthorTesting; |
| 4 |
|
| 5 |
use App::Yath::Tester qw/yath/; |
| 6 |
|
| 7 |
my $dir = __FILE__; |
| 8 |
$dir =~ s{\.t$}{}g; |
| 9 |
$dir =~ s{^\./}{}; |
| 10 |
|
| 11 |
run_tests('test'); |
| 12 |
run_test_command_only_cases(); |
| 13 |
|
| 14 |
my $project = "asgadfgds"; |
| 15 |
|
| 16 |
yath( |
| 17 |
command => 'start', |
| 18 |
pre => ['--project', $project], |
| 19 |
args => [], |
| 20 |
exit => 0, |
| 21 |
test => sub { |
| 22 |
run_tests('run'); |
| 23 |
yath(command => 'stop', args => [], exit => 0); |
| 24 |
} |
| 25 |
); |
| 26 |
|
| 27 |
sub run_tests { |
| 28 |
my ($cmd) = @_; |
| 29 |
|
| 30 |
yath( |
| 31 |
command => $cmd, |
| 32 |
pre => ['--project', $project], |
| 33 |
args => [$dir, '--ext=tx', '-r3'], |
| 34 |
log => 1, |
| 35 |
exit => 0, |
| 36 |
test => sub { |
| 37 |
my $out = shift; |
| 38 |
my $final = ($out->{log}->poll())[-2]; |
| 39 |
is($final->{facet_data}->{harness_final}->{pass}, T(), "Passed in log"); |
| 40 |
}, |
| 41 |
); |
| 42 |
|
| 43 |
yath( |
| 44 |
command => $cmd, |
| 45 |
pre => ['--project', $project], |
| 46 |
args => [$dir, '--ext=tx', '-r3', '--env-var' => "FAIL_ONCE=1", '-v'], |
| 47 |
log => 1, |
| 48 |
exit => 0, |
| 49 |
debug => 0, |
| 50 |
test => sub { |
| 51 |
my $out = shift; |
| 52 |
|
| 53 |
my $final = ($out->{log}->poll())[-2]; |
| 54 |
my $retry_data = $final->{facet_data}->{harness_final}->{retried}->[0]; |
| 55 |
ok($retry_data, "got retry data") or return; |
| 56 |
my ($uuid, $tries, $file, $status) = @$retry_data; |
| 57 |
is($tries, 2, "Tried twice"); |
| 58 |
like($file, qr{retry\.tx}, "Retried the right file"); |
| 59 |
is($status, 'YES', "Eventually passed"); |
| 60 |
}, |
| 61 |
); |
| 62 |
|
| 63 |
yath( |
| 64 |
command => $cmd, |
| 65 |
pre => ['--project', $project], |
| 66 |
args => [$dir, '--ext=tx', '-r3', '--env-var' => "FAIL_ALWAYS=1"], |
| 67 |
log => 1, |
| 68 |
exit => T(), |
| 69 |
test => sub { |
| 70 |
my $out = shift; |
| 71 |
my $final = ($out->{log}->poll())[-2]; |
| 72 |
my $retry_data = $final->{facet_data}->{harness_final}->{retried}->[0]; |
| 73 |
my ($uuid, $tries, $file, $status) = @$retry_data; |
| 74 |
|
| 75 |
is($tries, 4, "Tried 4 times: 1 run + 3 retries"); |
| 76 |
like($file, qr{retry\.tx}, "Retried the right file"); |
| 77 |
is($status, 'NO', "Never passed"); |
| 78 |
}, |
| 79 |
); |
| 80 |
} |
| 81 |
|
| 82 |
# Both cases below always use the "test" command, so the "run" pass of |
| 83 |
# run_tests() used to repeat them unchanged -- including a full 20 second |
| 84 |
# event timeout -- and assert the same things about the same run. |
| 85 |
sub run_test_command_only_cases { |
| 86 |
{ |
| 87 |
note q[Retrying a symlink]; |
| 88 |
|
| 89 |
my $sdir = $dir . '-symlinks'; |
| 90 |
my $symlink = "$sdir/symlink.tl"; |
| 91 |
|
| 92 |
unlink $symlink if -e $symlink; |
| 93 |
if ( eval{ symlink('retry.tx', $symlink) } ) { |
| 94 |
yath( |
| 95 |
command => 'test', |
| 96 |
args => [$sdir, '--ext=tl', '--retry' => 1, '--env-var' => "FAIL_ONCE=1", '-v' ], |
| 97 |
log => 1, |
| 98 |
exit => 0, |
| 99 |
test => sub { |
| 100 |
my $out = shift; |
| 101 |
|
| 102 |
my $final = ($out->{log}->poll())[-2]; |
| 103 |
my $retry_data = $final->{facet_data}->{harness_final}->{retried}->[0]; |
| 104 |
my ($uuid, $tries, $file, $status) = @$retry_data; |
| 105 |
|
| 106 |
is $tries, 2, 'retried a broken symlink'; |
| 107 |
is $file, 't/integration/retry-symlinks/symlink.tl', "using symlink name"; |
| 108 |
is $status, 'YES', 'Succeeded Eventually: YES'; |
| 109 |
|
| 110 |
unlike($out->{output}, qr{FAILED}, q[no failures]); |
| 111 |
}, |
| 112 |
); |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
{ |
| 117 |
note q[Retrying a test failing due to a timeout]; |
| 118 |
|
| 119 |
my $sdir = $dir . '-timeout'; |
| 120 |
yath( |
| 121 |
command => 'test', |
| 122 |
args => [$sdir, '--ext=tx', '--retry' => 1, '--env-var' => "FAIL_ONCE=1", '-v' ], |
| 123 |
log => 1, |
| 124 |
exit => 0, |
| 125 |
test => sub { |
| 126 |
my $out = shift; |
| 127 |
|
| 128 |
my $final = ($out->{log}->poll())[-2]; |
| 129 |
my $retry_data = $final->{facet_data}->{harness_final}->{retried}->[0]; |
| 130 |
my ($uuid, $tries, $file, $status) = @$retry_data; |
| 131 |
|
| 132 |
#note $out->{output}; |
| 133 |
|
| 134 |
is $tries, 2, 'retried a test when failing due to a timeout'; |
| 135 |
is $file, 't/integration/retry-timeout/retry.tx', "retry.txt test"; |
| 136 |
is $status, 'YES', 'Succeeded Eventually: YES'; |
| 137 |
|
| 138 |
unlike($out->{output}, qr{FAILED}, q[no failures]); |
| 139 |
}, |
| 140 |
); |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
done_testing; |