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.5 by root, Sat Jul 18 00:05:29 2009 UTC vs.
Revision 1.11 by root, Tue Aug 2 22:07:18 2011 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines