ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/67_tk_03_child.t
Revision: 1.13
Committed: Fri Mar 30 04:22:22 2012 UTC (12 years, 2 months ago) by root
Content type: application/x-troff
Branch: MAIN
Changes since 1.12: +7 -0 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 use POSIX ();
2
3 no warnings;
4
5 BEGIN {
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;
14 1..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.
15 EOF
16 exit 0;
17 }
18 }
19 }
20
21 use AnyEvent;
22
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::Tk;1} or ((print qq{1..0 # SKIP AnyEvent::Impl::Tk not loadable\n}), exit 0) }
25
26
27
28 $| = 1; print "1..50\n";
29
30 $AnyEvent::MAX_SIGNAL_LATENCY = 0.2;
31
32 for my $it ("", 1, 2, 3, 4) {
33 print "ok ${it}1\n";
34
35 AnyEvent::detect; # force-load event model
36
37 my $pid = fork;
38
39 defined $pid or die "unable to fork";
40
41 # work around Tk bug until it has been fixed.
42 #my $timer = AnyEvent->timer (after => 2, cb => sub { });
43
44 my $cv = AnyEvent->condvar;
45
46 unless ($pid) {
47 print "ok ${it}2 # child $$\n";
48
49 # POE hits a race condition when the child dies too quickly
50 # because it checks for child exit before installing the signal handler.
51 # seen in version 1.352 - earlier versions had the same bug, but
52 # polled for child exits regularly, so only caused a delay.
53 sleep 1 if $AnyEvent::MODEL eq "POE";
54
55 POSIX::_exit 3;
56 }
57 my $w = AnyEvent->child (pid => $pid, cb => sub {
58 print $pid == $_[0] ? "" : "not ", "ok ${it}3\ # $pid == $_[0]\n";
59 print 3 == ($_[1] >> 8) ? "" : "not ", "ok ${it}4 # 3 == $_[1] >> 8 ($_[1])\n";
60 $cv->broadcast;
61 });
62
63 $cv->recv;
64
65 my $pid2 = fork || POSIX::_exit 7;
66
67 my $cv2 = AnyEvent->condvar;
68
69 # Glib is the only model that doesn't support pid == 0
70 my $pid0 = $AnyEvent::MODEL eq "AnyEvent::Impl::Glib" ? $pid2 : 0;
71
72 my $w2 = AnyEvent->child (pid => $pid0, cb => sub {
73 print $pid2 == $_[0] ? "" : "not ", "ok ${it}5 # $pid2 == $_[0]\n";
74 print 7 == ($_[1] >> 8) ? "" : "not ", "ok ${it}6 # 7 == $_[1] >> 8 ($_[1])\n";
75 $cv2->broadcast;
76 });
77
78 my $error = AnyEvent->timer (after => 5, cb => sub {
79 print <<EOF;
80 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";
81 EOF
82 exit 0;
83 });
84
85 $cv2->recv;
86
87 print "ok ${it}7\n";
88 print "ok ${it}8\n";
89 print "ok ${it}9\n";
90 print "ok ", $it*10+10, "\n";
91 }
92
93
94
95