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

Comparing AnyEvent/t/69_ev_09_multi.t (file contents):
Revision 1.1 by root, Tue Aug 2 22:07:18 2011 UTC vs.
Revision 1.4 by root, Fri Aug 12 18:41:30 2011 UTC

1BEGIN {
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;
101..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
12 exit 0;
13 }
14 }
15}
16
1use AnyEvent; 17use AnyEvent;
2use AnyEvent::Util; 18use AnyEvent::Util;
3BEGIN { eval q{use AnyEvent::Impl::EV;1} or ((print qq{1..0 # SKIP AnyEvent::Impl::EV not loadable
4}), exit 0) }
5 19
20 BEGIN { $ENV{PERL_ANYEVENT_LOOP_TESTS} or ((print qq{1..0 # SKIP PERL_ANYEVENT_LOOP_TESTS not true\n}), exit 0) }
21 BEGIN { eval q{use AnyEvent::Impl::EV;1} or ((print qq{1..0 # SKIP AnyEvent::Impl::EV not loadable\n}), exit 0) }
22
23
24
6$| = 1; print "1..14\n"; 25$| = 1; print "1..15\n";
7 26
8print "ok 1\n"; 27print "ok 1\n";
9 28
10my ($a, $b) = AnyEvent::Util::portable_socketpair; 29my ($a, $b) = AnyEvent::Util::portable_socketpair;
11 30
12# I/O write 31# I/O write
13{ 32{
14 my $cv = AE::cv; 33 my $cv = AE::cv;
15 my $wt = AE::timer 0.1, 0, $cv; 34 my $wt = AE::timer 1, 0, $cv;
16 my $s = 0; 35 my $s = 0;
17 36
18 $cv->begin; my $wa = AE::io $a, 1, sub { $cv->end; $s |= 1 }; 37 $cv->begin; my $wa = AE::io $a, 1, sub { $cv->end; $s |= 1 };
19 $cv->begin; my $wb = AE::io $a, 1, sub { $cv->end; $s |= 2 }; 38 $cv->begin; my $wb = AE::io $a, 1, sub { $cv->end; $s |= 2 };
20 39
24} 43}
25 44
26# I/O read 45# I/O read
27{ 46{
28 my $cv = AE::cv; 47 my $cv = AE::cv;
29 my $wt = AE::timer 0.1, 0, $cv; 48 my $wt = AE::timer 0.01, 0, $cv;
30 my $s = 0; 49 my $s = 0;
31 50
32 my $wa = AE::io $a, 0, sub { $cv->end; $s |= 1 }; 51 my $wa = AE::io $a, 0, sub { $cv->end; $s |= 1 };
33 my $wb = AE::io $a, 0, sub { $cv->end; $s |= 2 }; 52 my $wb = AE::io $a, 0, sub { $cv->end; $s |= 2 };
34 53
37 print $s == 0 ? "" : "not ", "ok 3 # $s\n"; 56 print $s == 0 ? "" : "not ", "ok 3 # $s\n";
38 57
39 syswrite $b, "x"; 58 syswrite $b, "x";
40 59
41 $cv = AE::cv; 60 $cv = AE::cv;
42 $wt = AE::timer 0.1, 0, $cv; 61 $wt = AE::timer 1, 0, $cv;
43 62
44 $s = 0; 63 $s = 0;
45 $cv->begin; 64 $cv->begin;
46 $cv->begin; 65 $cv->begin;
47 $cv->recv; 66 $cv->recv;
49 print $s == 3 ? "" : "not ", "ok 4 # $s\n"; 68 print $s == 3 ? "" : "not ", "ok 4 # $s\n";
50 69
51 sysread $a, my $dummy, 1; 70 sysread $a, my $dummy, 1;
52 71
53 $cv = AE::cv; 72 $cv = AE::cv;
54 $wt = AE::timer 0.1, 0, $cv; 73 $wt = AE::timer 0.01, 0, $cv;
55 74
56 $s = 0; 75 $s = 0;
57 $cv->recv; 76 $cv->recv;
58 77
59 print $s == 0 ? "" : "not ", "ok 5 # $s\n"; 78 print $s == 0 ? "" : "not ", "ok 5 # $s\n";
60} 79}
61 80
62# signal 81# signal
63{ 82{
64 my $cv = AE::cv; 83 my $cv = AE::cv;
65 my $wt = AE::timer 0.1, 0, $cv; 84 my $wt = AE::timer 0.01, 0, $cv;
66 my $s = 0; 85 my $s = 0;
67 86
68 $cv->begin; my $wa = AE::signal INT => sub { $cv->end; $s |= 1 }; 87 $cv->begin; my $wa = AE::signal INT => sub { $cv->end; $s |= 1 };
69 $cv->begin; my $wb = AE::signal INT => sub { $cv->end; $s |= 2 }; 88 $cv->begin; my $wb = AE::signal INT => sub { $cv->end; $s |= 2 };
70 89
73 print $s == 0 ? "" : "not ", "ok 6 # $s\n"; 92 print $s == 0 ? "" : "not ", "ok 6 # $s\n";
74 93
75 kill INT => $$; 94 kill INT => $$;
76 95
77 $cv = AE::cv; 96 $cv = AE::cv;
78 $wt = AE::timer 0.1, 0, $cv; 97 $wt = AE::timer 0.01, 0, $cv;
79 98
80 $s = 0; 99 $s = 0;
81 $cv->recv; 100 $cv->recv;
82 101
83 print $s == 3 ? "" : "not ", "ok 7 # $s\n"; 102 print $s == 3 ? "" : "not ", "ok 7 # $s\n";
84 103
85 $cv = AE::cv; 104 $cv = AE::cv;
86 $wt = AE::timer 0.1, 0, $cv; 105 $wt = AE::timer 0.01, 0, $cv;
87 106
88 $s = 0; 107 $s = 0;
89 $cv->recv; 108 $cv->recv;
90 109
91 print $s == 0 ? "" : "not ", "ok 8 # $s\n"; 110 print $s == 0 ? "" : "not ", "ok 8 # $s\n";
94$AnyEvent::MAX_SIGNAL_LATENCY = 0.2; 113$AnyEvent::MAX_SIGNAL_LATENCY = 0.2;
95 114
96# child 115# child
97{ 116{
98 my $cv = AE::cv; 117 my $cv = AE::cv;
99 my $wt = AE::timer 0.1, 0, $cv; 118 my $wt = AE::timer 0.01, 0, $cv;
100 my $s = 0; 119 my $s = 0;
101 120
102 my $pid = fork; 121 my $pid = fork;
103 122
104 unless ($pid) { 123 unless ($pid) {
116 print $s == 0 ? "" : "not ", "ok 9 # $s\n"; 135 print $s == 0 ? "" : "not ", "ok 9 # $s\n";
117 136
118 kill 9, $pid; 137 kill 9, $pid;
119 138
120 $cv = AE::cv; 139 $cv = AE::cv;
121 $wt = AE::timer 0.1, 0, $cv; 140 $wt = AE::timer 0.01, 0, $cv;
122 141
123 $s = 0; 142 $s = 0;
124 $cv->recv; 143 $cv->recv;
125 144
126 print $s == 3 ? "" : "not ", "ok 10 # $s\n"; 145 print $s == 3 ? "" : "not ", "ok 10 # $s\n";
127 print $apid == $pid && $bpid == $pid ? "" : "not ", "ok 11 # $apid == $bpid == $pid\n"; 146 print $apid == $pid && $bpid == $pid ? "" : "not ", "ok 11 # $apid == $bpid == $pid\n";
128 print $astatus == 9 && $bstatus == 9 ? "" : "not ", "ok 12 # $astatus == $bstatus == 9\n"; 147 print $astatus == 9 && $bstatus == 9 ? "" : "not ", "ok 12 # $astatus == $bstatus == 9\n";
129 148
130 $cv = AE::cv; 149 $cv = AE::cv;
131 $wt = AE::timer 0.1, 0, $cv; 150 $wt = AE::timer 0.01, 0, $cv;
132 151
133 $s = 0; 152 $s = 0;
134 $cv->recv; 153 $cv->recv;
135 154
136 print $s == 0 ? "" : "not ", "ok 13 # $s\n"; 155 print $s == 0 ? "" : "not ", "ok 13 # $s\n";
137} 156}
138 157
158# timers (don't laugh, some event loops are more broken...)
159{
160 my $cv = AE::cv;
161 my $wt = AE::timer 1, 0, $cv;
162 my $s = 0;
163
164 $cv->begin; my $wa = AE::timer 0 , 0, sub { $cv->end; $s |= 1 };
165 $cv->begin; my $wb = AE::timer 0 , 0, sub { $cv->end; $s |= 2 };
166 $cv->begin; my $wc = AE::timer 0.01, 0, sub { $cv->end; $s |= 4 };
167
168 $cv->recv;
169
170 print $s == 7 ? "" : "not ", "ok 14 # $s\n";
171}
172
139print "ok 14\n"; 173print "ok 15\n";
140 174
141exit 0; 175exit 0;
142 176

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines