Created
June 22, 2010 19:59
-
-
Save hinrik/448979 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# vim: ts=2 sw=2 filetype=perl expandtab | |
use strict; | |
use warnings; | |
use Test::More; | |
use POE qw(Wheel::Run); | |
plan tests => 1; | |
POE::Session->create( | |
package_states => [ | |
(__PACKAGE__) => [qw( | |
_start | |
_child | |
timeout | |
)] | |
], | |
); | |
$poe_kernel->run(); | |
sub _start { | |
my ($kernel, $heap) = @_[KERNEL, HEAP]; | |
$kernel->delay('timeout', 5); | |
POE::Session->create( | |
inline_states => { | |
_start => sub { | |
my ($kernel, $heap) = @_[KERNEL, HEAP]; | |
$heap->{wheel} = POE::Wheel::Run->new( | |
Program => sub { die }, | |
StderrEvent => 'dummy', | |
CloseEvent => 'close', | |
); | |
$kernel->sig_child($heap->{wheel}->PID, 'sig_child'); | |
}, | |
sig_child => sub { | |
$_[HEAP]{dead}++; | |
delete $_[HEAP]{wheel} if $_[HEAP]{dead} == 2; | |
}, | |
close => sub { | |
$_[HEAP]{dead}++; | |
delete $_[HEAP]{wheel} if $_[HEAP]{dead} == 2; | |
}, | |
}, | |
); | |
} | |
sub _child { | |
my ($kernel, $heap, $reason) = @_[KERNEL, HEAP, ARG0]; | |
return if $reason eq 'create'; | |
$kernel->delay('timeout'); | |
is($reason, 'lose', 'Subsession died'); | |
} | |
sub timeout { | |
fail('Timed out'); | |
$_[KERNEL]->signal( $_[KERNEL], "DIE" ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment