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

Comparing AnyEvent/t/63_eventlib_03_child.t (file contents):
Revision 1.3 by root, Fri Jul 17 22:05:12 2009 UTC vs.
Revision 1.5 by root, Sat Jul 18 05:19:09 2009 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines