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

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines