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

Comparing AnyEvent/t/03_child.t (file contents):
Revision 1.8 by root, Tue Apr 22 05:12:19 2008 UTC vs.
Revision 1.18 by root, Mon Jul 20 06:00:42 2009 UTC

1$|=1; 1use POSIX ();
2
3no warnings;
4
2BEGIN { 5BEGIN {
3 print "1..7\n" 6 # check for broken perls
7 if ($^O =~ /mswin32/i) {
8 my $ok;
9 local $SIG{CHLD} = sub { $ok = 1 };
10 kill 'CHLD', 0;
11
12 unless ($ok) {
13 print <<EOF;
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.
15EOF
16 exit 0;
17 }
18 }
4} 19}
5 20
6use AnyEvent; 21use AnyEvent;
7use AnyEvent::Impl::Perl; 22use AnyEvent::Impl::Perl;
8 23
9print STDERR <<EOF; 24$| = 1; print "1..50\n";
10 25
11If the following test hangs for a long time you either found a bug in 26$AnyEvent::MAX_SIGNAL_LATENCY = 0.2;
12AnyEvent or, more likely, you have a defective perl (most windows perl
13distros are broken, cygwin perl works). If you do not rely on child
14handlers you can force the installation of this module and the rest will
15likely work. Otherwise upgrading to a working perl is recommended.
16EOF
17 27
28for my $it ("", 1, 2, 3, 4) {
18print "ok 1\n"; 29 print "ok ${it}1\n";
19 30
20my $pid = fork; 31 AnyEvent::detect; # force-load event model
21 32
33 my $pid = fork;
34
22defined $pid or die "unable to fork"; 35 defined $pid or die "unable to fork";
23 36
24# work around Tk bug until it has been fixed. 37# work around Tk bug until it has been fixed.
25#my $timer = AnyEvent->timer (after => 2, cb => sub { }); 38#my $timer = AnyEvent->timer (after => 2, cb => sub { });
26 39
27my $cv = AnyEvent->condvar; 40 my $cv = AnyEvent->condvar;
28 41
29unless ($pid) { 42 unless ($pid) {
30 print "ok 2\n"; 43 print "ok ${it}2\n";
31 exit 3; 44 POSIX::_exit 3;
32} 45 }
33 46
34my $w = AnyEvent->child (pid => $pid, cb => sub { 47 my $w = AnyEvent->child (pid => $pid, cb => sub {
35 print $pid == $_[0] ? "" : "not ", "ok 3\ # $pid == $_[0]\n"; 48 print $pid == $_[0] ? "" : "not ", "ok ${it}3\ # $pid == $_[0]\n";
36 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";
37 $cv->broadcast; 50 $cv->broadcast;
38}); 51 });
39 52
40$cv->wait; 53 $cv->wait;
41 54
42my $pid2 = fork || exit 7; 55 my $pid2 = fork || POSIX::_exit 7;
43 56
44my $cv2 = AnyEvent->condvar; 57 my $cv2 = AnyEvent->condvar;
45 58
46my $w2 = AnyEvent->child (pid => 0, cb => sub { 59 my $w2 = AnyEvent->child (pid => 0, cb => sub {
47 print $pid2 == $_[0] ? "" : "not ", "ok 5 # $pid2 == $_[0]\n"; 60 print $pid2 == $_[0] ? "" : "not ", "ok ${it}5 # $pid2 == $_[0]\n";
48 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";
49 $cv2->broadcast; 62 $cv2->broadcast;
50}); 63 });
51 64
52my $error = AnyEvent->timer (after => 5, cb => sub { 65 my $error = AnyEvent->timer (after => 5, cb => sub {
53 print <<EOF; 66 print <<EOF;
54Bail 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";
55EOF 68EOF
56 exit 0; 69 exit 0;
57}); 70 });
58 71
59$cv2->wait; 72 $cv2->wait;
60 73
61print "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}
62 79
63 80
64 81
65 82

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines