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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
#!/usr/bin/perl
=pod
=head1 NAME
timeout.t - Test suite for IPC::Run timeouts
=cut
use strict;
use warnings;
BEGIN {
$| = 1;
$^W = 1;
}
## Separate from run.t so run.t is not too slow.
use Test::More;
use IPC::Run qw( harness timeout );
plan tests => 26;
my $h;
my $t;
my $in;
my $out;
my $started;
$h = harness( [$^X], \$in, \$out, $t = timeout(1) );
ok( $h->isa('IPC::Run') );
ok( !!$t->is_reset );
ok( !$t->is_running );
ok( !$t->is_expired );
$started = time;
$h->start;
ok(1);
ok( !$t->is_reset );
ok( !!$t->is_running );
ok( !$t->is_expired );
$in = '';
eval { $h->pump };
# Older perls' Test.pms don't know what to do with qr//s
$@ =~ /IPC::Run: timeout/ ? ok(1) : is( $@, qr/IPC::Run: timeout/ );
SCOPE: {
my $elapsed = time - $started;
$elapsed >= 1 ? ok(1) : is( $elapsed, ">= 1" );
is( $t->interval, 1 );
ok( !$t->is_reset );
ok( !$t->is_running );
ok( !!$t->is_expired );
##
## Starting from an expired state
##
$started = time;
$h->start;
ok(1);
ok( !$t->is_reset );
ok( !!$t->is_running );
ok( !$t->is_expired );
$in = '';
eval { $h->pump };
$@ =~ /IPC::Run: timeout/ ? ok(1) : is( $@, qr/IPC::Run: timeout/ );
ok( !$t->is_reset );
ok( !$t->is_running );
ok( !!$t->is_expired );
}
SCOPE: {
my $elapsed = time - $started;
$elapsed >= 1 ? ok(1) : is( $elapsed, ">= 1" );
$h = harness( [$^X], \$in, \$out, timeout(1) );
$started = time;
$h->start;
$in = '';
eval { $h->pump };
$@ =~ /IPC::Run: timeout/ ? ok(1) : is( $@, qr/IPC::Run: timeout/ );
}
SCOPE: {
my $elapsed = time - $started;
$elapsed >= 1 ? ok(1) : is( $elapsed, ">= 1" );
}
{
$h = harness( [ $^X, '-e', 'sleep 1' ], timeout(180), debug => 0 );
my $started_at = time;
$h->start;
$h->finish;
my $finished_at = time;
ok( $finished_at - $started_at <= 2, 'not too slow to reap' )
or diag( $finished_at - $started_at . " seconds passed" );
}
|