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.8 by root, Sun Dec 5 11:41:46 2010 UTC vs.
Revision 1.12 by root, Tue Jul 30 23:14:33 2013 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines