1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
# Test the shutdown handler method in the SpeedyCGI module.
print "1..5\n";
my $testf = "/tmp/speedy.shutdown_done.$$";
my $scr = 't/scripts/shutdown';
unlink($testf);
utime time, time, $scr;
sleep 1;
sub run { my($whichtest, $nomaxruns) = @_;
my $maxruns = $nomaxruns ? '' : '-r2';
my $val = `$ENV{SPEEDY} -- $maxruns t/scripts/shutdown $testf $whichtest`;
sleep 1;
chomp $val;
return $val;
}
# The shutdown script that we run should create $testf when it
# shuts down. Test both add_shutdown_handler and set_shutdown_handler.
#
# Run twice by setting the maximum number of runs.
# After the first run, the file should not exist,
# but after the second run, it should exist.
#
for (my $i = 0; $i < 2; $i++) {
if (&run($i) > 0 && ! -f $testf && &run($i) > 0 && -f $testf) {
print "ok\n"
} else {
print "not ok\n";
}
unlink $testf;
}
# Test shutdown_next_time
if (&run(2) > 0 && -f $testf) {
print "ok\n";
} else {
print "not ok\n";
}
unlink $testf;
# Test shutdown_now
if (!&run(3) && -f $testf) {
print "ok\n";
} else {
print "not ok\n";
}
unlink $testf;
# Test whether a touch on the script causes the shutdown handler to be called
if (&run(1, 1) > 0 && utime(time, time, $scr) && &run(1, 1) > 0 && -f $testf) {
print "ok\n";
} else {
print "not ok\n";
}
unlink $testf;
|