--- AnyEvent/t/69_ev_03_child.t 2008/10/02 08:43:58 1.1 +++ AnyEvent/t/69_ev_03_child.t 2013/07/30 23:14:34 1.15 @@ -1,5 +1,6 @@ -$|=1; -BEGIN { unless (eval "require EV") { print "1..0 # skip because EV isn't installed"; exit } } +use POSIX (); + +no warnings; BEGIN { # check for broken perls @@ -10,66 +11,88 @@ unless ($ok) { print <timer (after => 2, cb => sub { }); + AnyEvent::detect; # force-load event model -my $cv = AnyEvent->condvar; + my $pid = fork; -unless ($pid) { - print "ok 2\n"; - exit 3; -} + defined $pid or die "unable to fork"; + + # work around Tk bug until it has been fixed. + #my $timer = AnyEvent->timer (after => 2, cb => sub { }); -my $w = AnyEvent->child (pid => $pid, cb => sub { - print $pid == $_[0] ? "" : "not ", "ok 3\ # $pid == $_[0]\n"; - print 3 == ($_[1] >> 8) ? "" : "not ", "ok 4 # 3 == $_[1] >> 8 ($_[1])\n"; - $cv->broadcast; -}); - -$cv->wait; - -my $pid2 = fork || exit 7; - -my $cv2 = AnyEvent->condvar; - -my $w2 = AnyEvent->child (pid => 0, cb => sub { - print $pid2 == $_[0] ? "" : "not ", "ok 5 # $pid2 == $_[0]\n"; - print 7 == ($_[1] >> 8) ? "" : "not ", "ok 6 # 7 == $_[1] >> 8 ($_[1])\n"; - $cv2->broadcast; -}); + my $cv = AnyEvent->condvar; -my $error = AnyEvent->timer (after => 5, cb => sub { - print <child (pid => $pid, cb => sub { + print $pid == $_[0] ? "" : "not ", "ok ${it}3\ # $pid == $_[0]\n"; + print 3 == ($_[1] >> 8) ? "" : "not ", "ok ${it}4 # 3 == $_[1] >> 8 ($_[1])\n"; + $cv->broadcast; + }); + + $cv->recv; + + my $pid2 = fork || do { + sleep 1 if $AnyEvent::MODEL eq "AnyEvent::Impl::POE"; + POSIX::_exit 7; + }; + + my $cv2 = AnyEvent->condvar; + + # Glib is the only model that doesn't support pid == 0 + my $pid0 = $AnyEvent::MODEL eq "AnyEvent::Impl::Glib" ? $pid2 : 0; + + my $w2 = AnyEvent->child (pid => $pid0, cb => sub { + print $pid2 == $_[0] ? "" : "not ", "ok ${it}5 # $pid2 == $_[0]\n"; + print 7 == ($_[1] >> 8) ? "" : "not ", "ok ${it}6 # 7 == $_[1] >> 8 ($_[1])\n"; + $cv2->broadcast; + }); + + my $error = AnyEvent->timer (after => 5, cb => sub { + print <wait; + $cv2->recv; -print "ok 7\n"; + print "ok ${it}7\n"; + print "ok ${it}8\n"; + print "ok ${it}9\n"; + print "ok ", $it*10+10, "\n"; +}