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

Comparing AnyEvent/t/68_poe_03_child.t (file contents):
Revision 1.4 by root, Fri Jul 17 22:05:12 2009 UTC vs.
Revision 1.11 by root, Tue Aug 2 22:07:18 2011 UTC

1use POSIX ();
2
3no warnings;
4
1BEGIN { 5BEGIN {
2 # check for broken perls 6 # check for broken perls
3 if ($^O =~ /mswin32/i) { 7 if ($^O =~ /mswin32/i) {
4 my $ok; 8 my $ok;
5 local $SIG{CHLD} = sub { $ok = 1 }; 9 local $SIG{CHLD} = sub { $ok = 1 };
6 kill 'CHLD', 0; 10 kill 'CHLD', 0;
7 11
8 unless ($ok) { 12 unless ($ok) {
9 print <<EOF; 13 print <<EOF;
101..0 # Your perl interpreter is badly BROKEN. Child watchers will not work, ever. Try upgrading to a newer perl or a working perl (cygwin's perl is known to work). If that is not an option, you should be able to use the remaining functionality of AnyEvent, but child watchers WILL NOT WORK. 141..0 # SKIP Your perl interpreter is badly BROKEN. Child watchers will not work, ever. Try upgrading to a newer perl or a working perl (cygwin's perl is known to work). If that is not an option, you should be able to use the remaining functionality of AnyEvent, but child watchers WILL NOT WORK.
11EOF 15EOF
12 exit 0; 16 exit 0;
13 } 17 }
14 } 18 }
15} 19}
16 20
17BEGIN { 21use AnyEvent;
18 $|=1; 22BEGIN { eval q{use AnyEvent::Impl::POE;1} or ((print qq{1..0 # SKIP AnyEvent::Impl::POE not loadable
19 print "1..7\n" 23}), exit 0) } $^W = 0;
20}
21 24
22use POSIX (); 25$| = 1; print "1..50\n";
23 26
24use AnyEvent; 27$AnyEvent::MAX_SIGNAL_LATENCY = 0.2;
25use AnyEvent::Impl::POE; $^W = 0;
26 28
27$AnyEvent::MAX_SIGNAL_LATENCY = 1; 29for my $it ("", 1, 2, 3, 4) {
30 print "ok ${it}1\n";
28 31
29print "ok 1\n"; 32 AnyEvent::detect; # force-load event model
30 33
31AnyEvent::detect; # force-load event model 34 my $pid = fork;
32 35
33my $pid = fork; 36 defined $pid or die "unable to fork";
34 37
35defined $pid or die "unable to fork"; 38 # work around Tk bug until it has been fixed.
39 #my $timer = AnyEvent->timer (after => 2, cb => sub { });
36 40
37# work around Tk bug until it has been fixed. 41 my $cv = AnyEvent->condvar;
38#my $timer = AnyEvent->timer (after => 2, cb => sub { });
39 42
40my $cv = AnyEvent->condvar; 43 unless ($pid) {
44 print "ok ${it}2\n";
45 POSIX::_exit 3;
46 }
41 47
42unless ($pid) { 48 my $w = AnyEvent->child (pid => $pid, cb => sub {
43 print "ok 2\n"; 49 print $pid == $_[0] ? "" : "not ", "ok ${it}3\ # $pid == $_[0]\n";
44 POSIX::_exit 3; 50 print 3 == ($_[1] >> 8) ? "" : "not ", "ok ${it}4 # 3 == $_[1] >> 8 ($_[1])\n";
45} 51 $cv->broadcast;
52 });
46 53
47my $w = AnyEvent->child (pid => $pid, cb => sub { 54 $cv->recv;
48 print $pid == $_[0] ? "" : "not ", "ok 3\ # $pid == $_[0]\n";
49 print 3 == ($_[1] >> 8) ? "" : "not ", "ok 4 # 3 == $_[1] >> 8 ($_[1])\n";
50 $cv->broadcast;
51});
52 55
53$cv->wait; 56 my $pid2 = fork || POSIX::_exit 7;
54 57
55my $pid2 = fork || POSIX::_exit 7; 58 my $cv2 = AnyEvent->condvar;
56 59
57my $cv2 = AnyEvent->condvar; 60 # Glib is the only model that doesn't support pid == 0
61 my $pid0 = $AnyEvent::MODEL eq "AnyEvent::Impl::Glib" ? $pid2 : 0;
58 62
59my $w2 = AnyEvent->child (pid => 0, cb => sub { 63 my $w2 = AnyEvent->child (pid => $pid0, cb => sub {
60 print $pid2 == $_[0] ? "" : "not ", "ok 5 # $pid2 == $_[0]\n"; 64 print $pid2 == $_[0] ? "" : "not ", "ok ${it}5 # $pid2 == $_[0]\n";
61 print 7 == ($_[1] >> 8) ? "" : "not ", "ok 6 # 7 == $_[1] >> 8 ($_[1])\n"; 65 print 7 == ($_[1] >> 8) ? "" : "not ", "ok ${it}6 # 7 == $_[1] >> 8 ($_[1])\n";
62 $cv2->broadcast; 66 $cv2->broadcast;
63}); 67 });
64 68
65my $error = AnyEvent->timer (after => 15, cb => sub { 69 my $error = AnyEvent->timer (after => 5, cb => sub {
66 print <<EOF; 70 print <<EOF;
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"; 71Bail 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 72EOF
69 exit 0; 73 exit 0;
70}); 74 });
71 75
72my $inter = AnyEvent->timer (after => 14, cb => sub {
73 print "not ok 5 # inter\n";
74 print "not ok 6 # inter\n";
75 $cv2->send; 76 $cv2->recv;
76});
77 77
78$cv2->wait;
79
80print "ok 7\n"; 78 print "ok ${it}7\n";
79 print "ok ${it}8\n";
80 print "ok ${it}9\n";
81 print "ok ", $it*10+10, "\n";
82}
81 83
82 84
83 85
84 86

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines