Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Neyuki discovered that detach_myself() was not working from _start,
nor was it working at all. This commit fixes the latter problem, but detach_myself() from _start is not completely fixed. Turned the test case into a regression test, and started t/regress for these things.
- Loading branch information
Showing
3 changed files
with
187 additions
and
55 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,120 @@ | |||
#!/usr/bin/perl -w | |||
# $Id$ | |||
|
|||
use strict; | |||
|
|||
$| = 1; | |||
|
|||
sub POE::Kernel::ASSERT_DEFAULT () { 1 } | |||
use POE; | |||
|
|||
print "1..10\n"; | |||
|
|||
my $test = 0; | |||
|
|||
POE::Session->create( | |||
inline_states => { | |||
_start => sub { | |||
$test++; | |||
print "not " unless $test == 1; | |||
print "ok $test # starting parent\n"; | |||
|
|||
$_[KERNEL]->yield('parent'); | |||
}, | |||
|
|||
_stop => sub { | |||
$test++; | |||
print "not " unless $test == 8; | |||
print "ok $test # stopping parent\n"; | |||
}, | |||
|
|||
_parent => sub { | |||
$test++; | |||
print "not ok $test # parent received _parent\n"; | |||
}, | |||
|
|||
_child => sub { | |||
|
|||
$test++; | |||
if ($test == 4) { | |||
print "not " unless ( | |||
$_[ARG1]->ID == 3 and | |||
$_[ARG0] eq "create" | |||
); | |||
print "ok $test # parent should receive _child create\n"; | |||
return; | |||
} | |||
|
|||
if ($test == 6) { | |||
print "not " unless ( | |||
$_[ARG1]->ID == 3 and | |||
$_[ARG0] eq "lose" | |||
); | |||
print "ok $test # parent should receive _child lose\n"; | |||
return; | |||
} | |||
|
|||
print "not ok $test # parent received _child $_[ARG0]\n"; | |||
}, | |||
|
|||
parent => sub { | |||
$test++; | |||
print "not " unless $test == 2; | |||
print "ok $test # parent spawning child\n"; | |||
|
|||
POE::Session->create( | |||
inline_states => { | |||
_start => sub { | |||
$test++; | |||
print "not " unless $test == 3; | |||
print "ok $test # child starting\n"; | |||
|
|||
$_[KERNEL]->yield('child'); | |||
}, | |||
|
|||
_stop => sub { | |||
$test++; | |||
print "not " unless $test == 10; | |||
print "ok $test # child stopping\n"; | |||
}, | |||
|
|||
_parent => sub { | |||
$test++; | |||
if ($test == 7) { | |||
print "not " unless ( | |||
$_[ARG0]->ID == 2 and | |||
$_[ARG1]->isa("POE::Kernel") | |||
); | |||
print "ok $test # child should receive _parent = kernel\n"; | |||
return; | |||
} | |||
|
|||
print "not ok $test # child given to $_[ARG1]\n"; | |||
}, | |||
|
|||
_child => sub { | |||
$test++; | |||
print "not ok $test # child received _child $_[ARG0]\n"; | |||
}, | |||
|
|||
child => sub { | |||
$test++; | |||
print "not " unless $test == 5; | |||
print "ok $test # child detaching itself\n"; | |||
|
|||
$_[KERNEL]->detach_myself; | |||
$_[KERNEL]->yield("done"); | |||
}, | |||
|
|||
done => sub { | |||
$test++; | |||
print "not " unless $test == 9; | |||
print "ok $test # child is done\n"; | |||
}, | |||
} | |||
); | |||
} # parent | |||
} # inline_states | |||
); | |||
|
|||
$poe_kernel->run; |