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

Comparing AnyEvent/t/66_ioasync_03_child.t (file contents):
Revision 1.11 by root, Tue Aug 2 20:02:46 2011 UTC vs.
Revision 1.17 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::IOAsync;1} or ((print qq{1..0 # SKIP AnyEvent::Impl::IOAsync not loadable 25 BEGIN { eval q{use AnyEvent::Impl::IOAsync;1} or ((print qq{1..0 # SKIP AnyEvent::Impl::IOAsync not loadable\n}), exit 0) }
23}), exit 0) } 26
27
24 28
25$| = 1; print "1..50\n"; 29$| = 1; print "1..50\n";
26 30
27$AnyEvent::MAX_SIGNAL_LATENCY = 0.2; 31$AnyEvent::MAX_SIGNAL_LATENCY = 0.2;
28 32
33 37
34 my $pid = fork; 38 my $pid = fork;
35 39
36 defined $pid or die "unable to fork"; 40 defined $pid or die "unable to fork";
37 41
38# work around Tk bug until it has been fixed. 42 # work around Tk bug until it has been fixed.
39#my $timer = AnyEvent->timer (after => 2, cb => sub { }); 43 #my $timer = AnyEvent->timer (after => 2, cb => sub { });
40 44
41 my $cv = AnyEvent->condvar; 45 my $cv = AnyEvent->condvar;
42 46
43 unless ($pid) { 47 unless ($pid) {
44 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
45 POSIX::_exit 3; 56 POSIX::_exit 3;
46 } 57 }
47
48 my $w = AnyEvent->child (pid => $pid, cb => sub { 58 my $w = AnyEvent->child (pid => $pid, cb => sub {
49 print $pid == $_[0] ? "" : "not ", "ok ${it}3\ # $pid == $_[0]\n"; 59 print $pid == $_[0] ? "" : "not ", "ok ${it}3\ # $pid == $_[0]\n";
50 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";
51 $cv->broadcast; 61 $cv->broadcast;
52 }); 62 });
53 63
54 $cv->recv; 64 $cv->recv;
55 65
56 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 };
57 70
58 my $cv2 = AnyEvent->condvar; 71 my $cv2 = AnyEvent->condvar;
59 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
60 my $w2 = AnyEvent->child (pid => 0, cb => sub { 76 my $w2 = AnyEvent->child (pid => $pid0, cb => sub {
61 print $pid2 == $_[0] ? "" : "not ", "ok ${it}5 # $pid2 == $_[0]\n"; 77 print $pid2 == $_[0] ? "" : "not ", "ok ${it}5 # $pid2 == $_[0]\n";
62 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";
63 $cv2->broadcast; 79 $cv2->broadcast;
64 }); 80 });
65 81

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines