ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/69_ev_03_child.t
Revision: 1.2
Committed: Thu Jul 9 22:49:18 2009 UTC (14 years, 11 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-4_82, rel-4_83
Changes since 1.1: +12 -6 lines
Log Message:
*** empty log message ***

File Contents

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