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

Comparing AnyEvent/t/65_event_03_child.t (file contents):
Revision 1.9 by root, Tue Aug 2 20:02:46 2011 UTC vs.
Revision 1.13 by root, Fri Mar 30 04:22:22 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::Event;1} or ((print qq{1..0 # SKIP AnyEvent::Impl::Event not loadable 24 BEGIN { eval q{use AnyEvent::Impl::Event;1} or ((print qq{1..0 # SKIP AnyEvent::Impl::Event not loadable\n}), exit 0) }
23}), exit 0) } 25
26
24 27
25$| = 1; print "1..50\n"; 28$| = 1; print "1..50\n";
26 29
27$AnyEvent::MAX_SIGNAL_LATENCY = 0.2; 30$AnyEvent::MAX_SIGNAL_LATENCY = 0.2;
28 31
33 36
34 my $pid = fork; 37 my $pid = fork;
35 38
36 defined $pid or die "unable to fork"; 39 defined $pid or die "unable to fork";
37 40
38# work around Tk bug until it has been fixed. 41 # work around Tk bug until it has been fixed.
39#my $timer = AnyEvent->timer (after => 2, cb => sub { }); 42 #my $timer = AnyEvent->timer (after => 2, cb => sub { });
40 43
41 my $cv = AnyEvent->condvar; 44 my $cv = AnyEvent->condvar;
42 45
43 unless ($pid) { 46 unless ($pid) {
44 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 "POE";
54
45 POSIX::_exit 3; 55 POSIX::_exit 3;
46 } 56 }
47
48 my $w = AnyEvent->child (pid => $pid, cb => sub { 57 my $w = AnyEvent->child (pid => $pid, cb => sub {
49 print $pid == $_[0] ? "" : "not ", "ok ${it}3\ # $pid == $_[0]\n"; 58 print $pid == $_[0] ? "" : "not ", "ok ${it}3\ # $pid == $_[0]\n";
50 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";
51 $cv->broadcast; 60 $cv->broadcast;
52 }); 61 });
55 64
56 my $pid2 = fork || POSIX::_exit 7; 65 my $pid2 = fork || POSIX::_exit 7;
57 66
58 my $cv2 = AnyEvent->condvar; 67 my $cv2 = AnyEvent->condvar;
59 68
69 # Glib is the only model that doesn't support pid == 0
70 my $pid0 = $AnyEvent::MODEL eq "AnyEvent::Impl::Glib" ? $pid2 : 0;
71
60 my $w2 = AnyEvent->child (pid => 0, cb => sub { 72 my $w2 = AnyEvent->child (pid => $pid0, cb => sub {
61 print $pid2 == $_[0] ? "" : "not ", "ok ${it}5 # $pid2 == $_[0]\n"; 73 print $pid2 == $_[0] ? "" : "not ", "ok ${it}5 # $pid2 == $_[0]\n";
62 print 7 == ($_[1] >> 8) ? "" : "not ", "ok ${it}6 # 7 == $_[1] >> 8 ($_[1])\n"; 74 print 7 == ($_[1] >> 8) ? "" : "not ", "ok ${it}6 # 7 == $_[1] >> 8 ($_[1])\n";
63 $cv2->broadcast; 75 $cv2->broadcast;
64 }); 76 });
65 77

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines