ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/03_child.t
(Generate patch)

Comparing AnyEvent/t/03_child.t (file contents):
Revision 1.19 by root, Wed Dec 29 04:16:33 2010 UTC vs.
Revision 1.23 by root, Fri Mar 30 04:22:22 2012 UTC

32 32
33 my $pid = fork; 33 my $pid = fork;
34 34
35 defined $pid or die "unable to fork"; 35 defined $pid or die "unable to fork";
36 36
37# work around Tk bug until it has been fixed. 37 # work around Tk bug until it has been fixed.
38#my $timer = AnyEvent->timer (after => 2, cb => sub { }); 38 #my $timer = AnyEvent->timer (after => 2, cb => sub { });
39 39
40 my $cv = AnyEvent->condvar; 40 my $cv = AnyEvent->condvar;
41 41
42 unless ($pid) { 42 unless ($pid) {
43 print "ok ${it}2\n"; 43 print "ok ${it}2 # child $$\n";
44
45 # POE hits a race condition when the child dies too quickly
46 # because it checks for child exit before installing the signal handler.
47 # seen in version 1.352 - earlier versions had the same bug, but
48 # polled for child exits regularly, so only caused a delay.
49 sleep 1 if $AnyEvent::MODEL eq "POE";
50
44 POSIX::_exit 3; 51 POSIX::_exit 3;
45 } 52 }
46
47 my $w = AnyEvent->child (pid => $pid, cb => sub { 53 my $w = AnyEvent->child (pid => $pid, cb => sub {
48 print $pid == $_[0] ? "" : "not ", "ok ${it}3\ # $pid == $_[0]\n"; 54 print $pid == $_[0] ? "" : "not ", "ok ${it}3\ # $pid == $_[0]\n";
49 print 3 == ($_[1] >> 8) ? "" : "not ", "ok ${it}4 # 3 == $_[1] >> 8 ($_[1])\n"; 55 print 3 == ($_[1] >> 8) ? "" : "not ", "ok ${it}4 # 3 == $_[1] >> 8 ($_[1])\n";
50 $cv->broadcast; 56 $cv->broadcast;
51 }); 57 });
52 58
53 $cv->wait; 59 $cv->recv;
54 60
55 my $pid2 = fork || POSIX::_exit 7; 61 my $pid2 = fork || POSIX::_exit 7;
56 62
57 my $cv2 = AnyEvent->condvar; 63 my $cv2 = AnyEvent->condvar;
58 64
65 # Glib is the only model that doesn't support pid == 0
66 my $pid0 = $AnyEvent::MODEL eq "AnyEvent::Impl::Glib" ? $pid2 : 0;
67
59 my $w2 = AnyEvent->child (pid => 0, cb => sub { 68 my $w2 = AnyEvent->child (pid => $pid0, cb => sub {
60 print $pid2 == $_[0] ? "" : "not ", "ok ${it}5 # $pid2 == $_[0]\n"; 69 print $pid2 == $_[0] ? "" : "not ", "ok ${it}5 # $pid2 == $_[0]\n";
61 print 7 == ($_[1] >> 8) ? "" : "not ", "ok ${it}6 # 7 == $_[1] >> 8 ($_[1])\n"; 70 print 7 == ($_[1] >> 8) ? "" : "not ", "ok ${it}6 # 7 == $_[1] >> 8 ($_[1])\n";
62 $cv2->broadcast; 71 $cv2->broadcast;
63 }); 72 });
64 73
67Bail out! No child exit detected. This is either a bug in AnyEvent or a bug in your Perl (mostly some windows distributions suffer from that): child watchers might not work properly on this platform. You can force installation of this module if you do not rely on child watchers, or you could upgrade to a working version of Perl for your platform.\n"; 76Bail out! No child exit detected. This is either a bug in AnyEvent or a bug in your Perl (mostly some windows distributions suffer from that): child watchers might not work properly on this platform. You can force installation of this module if you do not rely on child watchers, or you could upgrade to a working version of Perl for your platform.\n";
68EOF 77EOF
69 exit 0; 78 exit 0;
70 }); 79 });
71 80
72 $cv2->wait; 81 $cv2->recv;
73 82
74 print "ok ${it}7\n"; 83 print "ok ${it}7\n";
75 print "ok ${it}8\n"; 84 print "ok ${it}8\n";
76 print "ok ${it}9\n"; 85 print "ok ${it}9\n";
77 print "ok ", $it*10+10, "\n"; 86 print "ok ", $it*10+10, "\n";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines