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

Comparing AnyEvent/t/63_eventlib_03_child.t (file contents):
Revision 1.10 by root, Tue Aug 2 22:32:59 2011 UTC vs.
Revision 1.11 by root, Wed Apr 4 02:18:30 2012 UTC

17 } 17 }
18 } 18 }
19} 19}
20 20
21use AnyEvent; 21use AnyEvent;
22
23 BEGIN { $ENV{PERL_ANYEVENT_LOOP_TESTS} or ((print qq{1..0 # SKIP PERL_ANYEVENT_LOOP_TESTS not true\n}), exit 0) }
22BEGIN { eval q{use AnyEvent::Impl::EventLib;1} or ((print qq{1..0 # SKIP AnyEvent::Impl::EventLib not loadable}), exit 0) } 24 BEGIN { eval q{use AnyEvent::Impl::EventLib;1} or ((print qq{1..0 # SKIP AnyEvent::Impl::EventLib not loadable\n}), exit 0) }
25
26
23 27
24$| = 1; print "1..50\n"; 28$| = 1; print "1..50\n";
25 29
26$AnyEvent::MAX_SIGNAL_LATENCY = 0.2; 30$AnyEvent::MAX_SIGNAL_LATENCY = 0.2;
27 31
32 36
33 my $pid = fork; 37 my $pid = fork;
34 38
35 defined $pid or die "unable to fork"; 39 defined $pid or die "unable to fork";
36 40
37# work around Tk bug until it has been fixed. 41 # work around Tk bug until it has been fixed.
38#my $timer = AnyEvent->timer (after => 2, cb => sub { }); 42 #my $timer = AnyEvent->timer (after => 2, cb => sub { });
39 43
40 my $cv = AnyEvent->condvar; 44 my $cv = AnyEvent->condvar;
41 45
42 unless ($pid) { 46 unless ($pid) {
43 print "ok ${it}2\n"; 47 print "ok ${it}2 # child $$\n";
48
49 # POE hits a race condition when the child dies too quickly
50 # because it checks for child exit before installing the signal handler.
51 # seen in version 1.352 - earlier versions had the same bug, but
52 # polled for child exits regularly, so only caused a delay.
53 sleep 1 if $AnyEvent::MODEL eq "AnyEvent::Impl::POE";
54
44 POSIX::_exit 3; 55 POSIX::_exit 3;
45 } 56 }
46
47 my $w = AnyEvent->child (pid => $pid, cb => sub { 57 my $w = AnyEvent->child (pid => $pid, cb => sub {
48 print $pid == $_[0] ? "" : "not ", "ok ${it}3\ # $pid == $_[0]\n"; 58 print $pid == $_[0] ? "" : "not ", "ok ${it}3\ # $pid == $_[0]\n";
49 print 3 == ($_[1] >> 8) ? "" : "not ", "ok ${it}4 # 3 == $_[1] >> 8 ($_[1])\n"; 59 print 3 == ($_[1] >> 8) ? "" : "not ", "ok ${it}4 # 3 == $_[1] >> 8 ($_[1])\n";
50 $cv->broadcast; 60 $cv->broadcast;
51 }); 61 });
52 62
53 $cv->wait; 63 $cv->recv;
54 64
55 my $pid2 = fork || POSIX::_exit 7; 65 my $pid2 = fork || do {
66 sleep 1 if $AnyEvent::MODEL eq "AnyEvent::Impl::POE";
67 POSIX::_exit 7;
68 };
56 69
57 my $cv2 = AnyEvent->condvar; 70 my $cv2 = AnyEvent->condvar;
58 71
72 # Glib is the only model that doesn't support pid == 0
73 my $pid0 = $AnyEvent::MODEL eq "AnyEvent::Impl::Glib" ? $pid2 : 0;
74
59 my $w2 = AnyEvent->child (pid => 0, cb => sub { 75 my $w2 = AnyEvent->child (pid => $pid0, cb => sub {
60 print $pid2 == $_[0] ? "" : "not ", "ok ${it}5 # $pid2 == $_[0]\n"; 76 print $pid2 == $_[0] ? "" : "not ", "ok ${it}5 # $pid2 == $_[0]\n";
61 print 7 == ($_[1] >> 8) ? "" : "not ", "ok ${it}6 # 7 == $_[1] >> 8 ($_[1])\n"; 77 print 7 == ($_[1] >> 8) ? "" : "not ", "ok ${it}6 # 7 == $_[1] >> 8 ($_[1])\n";
62 $cv2->broadcast; 78 $cv2->broadcast;
63 }); 79 });
64 80
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"; 83Bail 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 84EOF
69 exit 0; 85 exit 0;
70 }); 86 });
71 87
72 $cv2->wait; 88 $cv2->recv;
73 89
74 print "ok ${it}7\n"; 90 print "ok ${it}7\n";
75 print "ok ${it}8\n"; 91 print "ok ${it}8\n";
76 print "ok ${it}9\n"; 92 print "ok ${it}9\n";
77 print "ok ", $it*10+10, "\n"; 93 print "ok ", $it*10+10, "\n";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines