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

Comparing AnyEvent/t/69_ev_03_child.t (file contents):
Revision 1.2 by root, Thu Jul 9 22:49:18 2009 UTC vs.
Revision 1.11 by root, Fri Aug 12 18:41:30 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;
19 print "1..7\n"
20}
21 22
22use POSIX (); 23 BEGIN { $ENV{PERL_ANYEVENT_LOOP_TESTS} or ((print qq{1..0 # SKIP PERL_ANYEVENT_LOOP_TESTS not true\n}), exit 0) }
24 BEGIN { eval q{use AnyEvent::Impl::EV;1} or ((print qq{1..0 # SKIP AnyEvent::Impl::EV not loadable\n}), exit 0) }
25
26
23 27
24use AnyEvent; 28$| = 1; print "1..50\n";
25use AnyEvent::Impl::EV;
26 29
27print "ok 1\n"; 30$AnyEvent::MAX_SIGNAL_LATENCY = 0.2;
28 31
29AnyEvent::detect; # force-load event model 32for my $it ("", 1, 2, 3, 4) {
33 print "ok ${it}1\n";
30 34
31my $pid = fork; 35 AnyEvent::detect; # force-load event model
32 36
33defined $pid or die "unable to fork"; 37 my $pid = fork;
34 38
35# work around Tk bug until it has been fixed. 39 defined $pid or die "unable to fork";
36#my $timer = AnyEvent->timer (after => 2, cb => sub { });
37 40
38my $cv = AnyEvent->condvar; 41 # work around Tk bug until it has been fixed.
42 #my $timer = AnyEvent->timer (after => 2, cb => sub { });
39 43
40unless ($pid) { 44 my $cv = AnyEvent->condvar;
41 print "ok 2\n";
42 POSIX::_exit 3;
43}
44 45
45my $w = AnyEvent->child (pid => $pid, cb => sub { 46 unless ($pid) {
46 print $pid == $_[0] ? "" : "not ", "ok 3\ # $pid == $_[0]\n"; 47 print "ok ${it}2\n";
47 print 3 == ($_[1] >> 8) ? "" : "not ", "ok 4 # 3 == $_[1] >> 8 ($_[1])\n"; 48 POSIX::_exit 3;
48 $cv->broadcast; 49 }
49});
50 50
51$cv->wait; 51 my $w = AnyEvent->child (pid => $pid, cb => sub {
52 print $pid == $_[0] ? "" : "not ", "ok ${it}3\ # $pid == $_[0]\n";
53 print 3 == ($_[1] >> 8) ? "" : "not ", "ok ${it}4 # 3 == $_[1] >> 8 ($_[1])\n";
54 $cv->broadcast;
55 });
52 56
53my $pid2 = fork || POSIX::_exit 7; 57 $cv->recv;
54 58
55my $cv2 = AnyEvent->condvar; 59 my $pid2 = fork || POSIX::_exit 7;
56 60
57my $w2 = AnyEvent->child (pid => 0, cb => sub { 61 my $cv2 = AnyEvent->condvar;
58 print $pid2 == $_[0] ? "" : "not ", "ok 5 # $pid2 == $_[0]\n";
59 print 7 == ($_[1] >> 8) ? "" : "not ", "ok 6 # 7 == $_[1] >> 8 ($_[1])\n";
60 $cv2->broadcast;
61});
62 62
63 # Glib is the only model that doesn't support pid == 0
64 my $pid0 = $AnyEvent::MODEL eq "AnyEvent::Impl::Glib" ? $pid2 : 0;
65
66 my $w2 = AnyEvent->child (pid => $pid0, cb => sub {
67 print $pid2 == $_[0] ? "" : "not ", "ok ${it}5 # $pid2 == $_[0]\n";
68 print 7 == ($_[1] >> 8) ? "" : "not ", "ok ${it}6 # 7 == $_[1] >> 8 ($_[1])\n";
69 $cv2->broadcast;
70 });
71
63my $error = AnyEvent->timer (after => 15, cb => sub { 72 my $error = AnyEvent->timer (after => 5, cb => sub {
64 print <<EOF; 73 print <<EOF;
65Bail 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"; 74Bail 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";
66EOF 75EOF
67 exit 0; 76 exit 0;
68}); 77 });
69 78
70my $inter = AnyEvent->timer (after => 14, cb => sub {
71 print "not ok 5 # inter\n";
72 print "not ok 6 # inter\n";
73 $cv2->send; 79 $cv2->recv;
74});
75 80
76$cv2->wait;
77
78print "ok 7\n"; 81 print "ok ${it}7\n";
82 print "ok ${it}8\n";
83 print "ok ${it}9\n";
84 print "ok ", $it*10+10, "\n";
85}
79 86
80 87
81 88
82 89

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines