OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library dart.pkg.isolate.isolaterunner_test; | 5 library isolate.test.ports_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:isolate'; | 8 import 'dart:isolate'; |
9 | 9 |
10 import 'package:isolate/ports.dart'; | 10 import 'package:isolate/ports.dart'; |
11 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
12 | 12 |
13 const Duration MS = const Duration(milliseconds: 1); | 13 const Duration MS = const Duration(milliseconds: 1); |
14 | 14 |
15 main() { | 15 main() { |
16 testSingleCallbackPort(); | 16 group('SingleCallbackPort', testSingleCallbackPort); |
17 testSingleCompletePort(); | 17 group('SingleCompletePort', testSingleCompletePort); |
18 testSingleResponseFuture(); | 18 group('SingleResponseFuture', testSingleResponseFuture); |
19 testSingleResultFuture(); | 19 group('SingleResponseFuture', testSingleResultFuture); |
20 testSingleResponseChannel(); | 20 group('SingleResponseChannel', testSingleResponseChannel); |
21 } | 21 } |
22 | 22 |
23 void testSingleCallbackPort() { | 23 void testSingleCallbackPort() { |
24 test("singleCallbackValue", () { | 24 test("Value", () { |
25 Completer completer = new Completer.sync(); | 25 Completer completer = new Completer.sync(); |
26 SendPort p = singleCallbackPort(completer.complete); | 26 SendPort p = singleCallbackPort(completer.complete); |
27 p.send(42); | 27 p.send(42); |
28 return completer.future.then((v) { | 28 return completer.future.then((v) { |
29 expect(v, 42); | 29 expect(v, 42); |
30 }); | 30 }); |
31 }); | 31 }); |
32 | 32 |
33 test("singleCallbackFirstValue", () { | 33 test("FirstValue", () { |
34 Completer completer = new Completer.sync(); | 34 Completer completer = new Completer.sync(); |
35 SendPort p = singleCallbackPort(completer.complete); | 35 SendPort p = singleCallbackPort(completer.complete); |
36 p.send(42); | 36 p.send(42); |
37 p.send(37); | 37 p.send(37); |
38 return completer.future.then((v) { | 38 return completer.future.then((v) { |
39 expect(v, 42); | 39 expect(v, 42); |
40 }); | 40 }); |
41 }); | 41 }); |
42 test("singleCallbackValue", () { | 42 test("Value", () { |
43 Completer completer = new Completer.sync(); | 43 Completer completer = new Completer.sync(); |
44 SendPort p = singleCallbackPort(completer.complete); | 44 SendPort p = singleCallbackPort(completer.complete); |
45 p.send(42); | 45 p.send(42); |
46 return completer.future.then((v) { | 46 return completer.future.then((v) { |
47 expect(v, 42); | 47 expect(v, 42); |
48 }); | 48 }); |
49 }); | 49 }); |
50 | 50 |
51 test("singleCallbackValueBeforeTimeout", () { | 51 test("ValueBeforeTimeout", () { |
52 Completer completer = new Completer.sync(); | 52 Completer completer = new Completer.sync(); |
53 SendPort p = singleCallbackPort(completer.complete, timeout: MS * 500); | 53 SendPort p = singleCallbackPort(completer.complete, timeout: MS * 500); |
54 p.send(42); | 54 p.send(42); |
55 return completer.future.then((v) { | 55 return completer.future.then((v) { |
56 expect(v, 42); | 56 expect(v, 42); |
57 }); | 57 }); |
58 }); | 58 }); |
59 | 59 |
60 test("singleCallbackTimeout", () { | 60 test("Timeout", () { |
61 Completer completer = new Completer.sync(); | 61 Completer completer = new Completer.sync(); |
62 singleCallbackPort(completer.complete, timeout: MS * 100, timeoutValue: 37); | 62 singleCallbackPort(completer.complete, timeout: MS * 100, timeoutValue: 37); |
63 return completer.future.then((v) { | 63 return completer.future.then((v) { |
64 expect(v, 37); | 64 expect(v, 37); |
65 }); | 65 }); |
66 }); | 66 }); |
67 | 67 |
68 test("singleCallbackTimeoutFirst", () { | 68 test("TimeoutFirst", () { |
69 Completer completer = new Completer.sync(); | 69 Completer completer = new Completer.sync(); |
70 SendPort p = singleCallbackPort(completer.complete, | 70 SendPort p = singleCallbackPort(completer.complete, |
71 timeout: MS * 100, | 71 timeout: MS * 100, |
72 timeoutValue: 37); | 72 timeoutValue: 37); |
73 new Timer(MS * 500, () => p.send(42)); | 73 new Timer(MS * 500, () => p.send(42)); |
74 return completer.future.then((v) { | 74 return completer.future.then((v) { |
75 expect(v, 37); | 75 expect(v, 37); |
76 }); | 76 }); |
77 }); | 77 }); |
78 } | 78 } |
79 | 79 |
80 | 80 |
81 void testSingleCompletePort() { | 81 void testSingleCompletePort() { |
82 test("singleCompleteValue", () { | 82 test("Value", () { |
83 Completer completer = new Completer.sync(); | 83 Completer completer = new Completer.sync(); |
84 SendPort p = singleCompletePort(completer); | 84 SendPort p = singleCompletePort(completer); |
85 p.send(42); | 85 p.send(42); |
86 return completer.future.then((v) { | 86 return completer.future.then((v) { |
87 expect(v, 42); | 87 expect(v, 42); |
88 }); | 88 }); |
89 }); | 89 }); |
90 | 90 |
91 test("singleCompleteValueCallback", () { | 91 test("ValueCallback", () { |
92 Completer completer = new Completer.sync(); | 92 Completer completer = new Completer.sync(); |
93 SendPort p = singleCompletePort(completer, callback: (v) { | 93 SendPort p = singleCompletePort(completer, callback: (v) { |
94 expect(42, v); | 94 expect(42, v); |
95 return 87; | 95 return 87; |
96 }); | 96 }); |
97 p.send(42); | 97 p.send(42); |
98 return completer.future.then((v) { | 98 return completer.future.then((v) { |
99 expect(v, 87); | 99 expect(v, 87); |
100 }); | 100 }); |
101 }); | 101 }); |
102 | 102 |
103 test("singleCompleteValueCallbackFuture", () { | 103 test("ValueCallbackFuture", () { |
104 Completer completer = new Completer.sync(); | 104 Completer completer = new Completer.sync(); |
105 SendPort p = singleCompletePort(completer, callback: (v) { | 105 SendPort p = singleCompletePort(completer, callback: (v) { |
106 expect(42, v); | 106 expect(42, v); |
107 return new Future.delayed(MS * 500, | 107 return new Future.delayed(MS * 500, |
108 () => 88); | 108 () => 88); |
109 }); | 109 }); |
110 p.send(42); | 110 p.send(42); |
111 return completer.future.then((v) { | 111 return completer.future.then((v) { |
112 expect(v, 88); | 112 expect(v, 88); |
113 }); | 113 }); |
114 }); | 114 }); |
115 | 115 |
116 test("singleCompleteValueCallbackThrows", () { | 116 test("ValueCallbackThrows", () { |
117 Completer completer = new Completer.sync(); | 117 Completer completer = new Completer.sync(); |
118 SendPort p = singleCompletePort(completer, callback: (v) { | 118 SendPort p = singleCompletePort(completer, callback: (v) { |
119 expect(42, v); | 119 expect(42, v); |
120 throw 89; | 120 throw 89; |
121 }); | 121 }); |
122 p.send(42); | 122 p.send(42); |
123 return completer.future.then((v) { | 123 return completer.future.then((v) { |
124 fail("unreachable"); | 124 fail("unreachable"); |
125 }, onError: (e, s) { | 125 }, onError: (e, s) { |
126 expect(e, 89); | 126 expect(e, 89); |
127 }); | 127 }); |
128 }); | 128 }); |
129 | 129 |
130 test("singleCompleteValueCallbackThrowsFuture", () { | 130 test("ValueCallbackThrowsFuture", () { |
131 Completer completer = new Completer.sync(); | 131 Completer completer = new Completer.sync(); |
132 SendPort p = singleCompletePort(completer, callback: (v) { | 132 SendPort p = singleCompletePort(completer, callback: (v) { |
133 expect(42, v); | 133 expect(42, v); |
134 return new Future.error(90); | 134 return new Future.error(90); |
135 }); | 135 }); |
136 p.send(42); | 136 p.send(42); |
137 return completer.future.then((v) { | 137 return completer.future.then((v) { |
138 fail("unreachable"); | 138 fail("unreachable"); |
139 }, onError: (e, s) { | 139 }, onError: (e, s) { |
140 expect(e, 90); | 140 expect(e, 90); |
141 }); | 141 }); |
142 }); | 142 }); |
143 | 143 |
144 test("singleCompleteFirstValue", () { | 144 test("FirstValue", () { |
145 Completer completer = new Completer.sync(); | 145 Completer completer = new Completer.sync(); |
146 SendPort p = singleCompletePort(completer); | 146 SendPort p = singleCompletePort(completer); |
147 p.send(42); | 147 p.send(42); |
148 p.send(37); | 148 p.send(37); |
149 return completer.future.then((v) { | 149 return completer.future.then((v) { |
150 expect(v, 42); | 150 expect(v, 42); |
151 }); | 151 }); |
152 }); | 152 }); |
153 | 153 |
154 test("singleCompleteFirstValueCallback", () { | 154 test("FirstValueCallback", () { |
155 Completer completer = new Completer.sync(); | 155 Completer completer = new Completer.sync(); |
156 SendPort p = singleCompletePort(completer, callback: (v) { | 156 SendPort p = singleCompletePort(completer, callback: (v) { |
157 expect(v, 42); | 157 expect(v, 42); |
158 return 87; | 158 return 87; |
159 }); | 159 }); |
160 p.send(42); | 160 p.send(42); |
161 p.send(37); | 161 p.send(37); |
162 return completer.future.then((v) { | 162 return completer.future.then((v) { |
163 expect(v, 87); | 163 expect(v, 87); |
164 }); | 164 }); |
165 }); | 165 }); |
166 | 166 |
167 test("singleCompleteValueBeforeTimeout", () { | 167 test("ValueBeforeTimeout", () { |
168 Completer completer = new Completer.sync(); | 168 Completer completer = new Completer.sync(); |
169 SendPort p = singleCompletePort(completer, timeout: MS * 500); | 169 SendPort p = singleCompletePort(completer, timeout: MS * 500); |
170 p.send(42); | 170 p.send(42); |
171 return completer.future.then((v) { | 171 return completer.future.then((v) { |
172 expect(v, 42); | 172 expect(v, 42); |
173 }); | 173 }); |
174 }); | 174 }); |
175 | 175 |
176 test("singleCompleteTimeout", () { | 176 test("Timeout", () { |
177 Completer completer = new Completer.sync(); | 177 Completer completer = new Completer.sync(); |
178 singleCompletePort(completer, timeout: MS * 100); | 178 singleCompletePort(completer, timeout: MS * 100); |
179 return completer.future.then((v) { | 179 return completer.future.then((v) { |
180 fail("unreachable"); | 180 fail("unreachable"); |
181 }, onError: (e, s) { | 181 }, onError: (e, s) { |
182 expect(e is TimeoutException, isTrue); | 182 expect(e is TimeoutException, isTrue); |
183 }); | 183 }); |
184 }); | 184 }); |
185 | 185 |
186 test("singleCompleteTimeoutCallback", () { | 186 test("TimeoutCallback", () { |
187 Completer completer = new Completer.sync(); | 187 Completer completer = new Completer.sync(); |
188 singleCompletePort(completer, timeout: MS * 100, onTimeout: () => 87); | 188 singleCompletePort(completer, timeout: MS * 100, onTimeout: () => 87); |
189 return completer.future.then((v) { | 189 return completer.future.then((v) { |
190 expect(v, 87); | 190 expect(v, 87); |
191 }); | 191 }); |
192 }); | 192 }); |
193 | 193 |
194 test("singleCompleteTimeoutCallbackThrows", () { | 194 test("TimeoutCallbackThrows", () { |
195 Completer completer = new Completer.sync(); | 195 Completer completer = new Completer.sync(); |
196 singleCompletePort(completer, timeout: MS * 100, onTimeout: () => throw 91); | 196 singleCompletePort(completer, timeout: MS * 100, onTimeout: () => throw 91); |
197 return completer.future.then((v) { | 197 return completer.future.then((v) { |
198 fail("unreachable"); | 198 fail("unreachable"); |
199 }, onError: (e, s) { | 199 }, onError: (e, s) { |
200 expect(e, 91); | 200 expect(e, 91); |
201 }); | 201 }); |
202 }); | 202 }); |
203 | 203 |
204 test("singleCompleteTimeoutCallbackFuture", () { | 204 test("TimeoutCallbackFuture", () { |
205 Completer completer = new Completer.sync(); | 205 Completer completer = new Completer.sync(); |
206 singleCompletePort(completer, | 206 singleCompletePort(completer, |
207 timeout: MS * 100, | 207 timeout: MS * 100, |
208 onTimeout: () => new Future.value(87)); | 208 onTimeout: () => new Future.value(87)); |
209 return completer.future.then((v) { | 209 return completer.future.then((v) { |
210 expect(v, 87); | 210 expect(v, 87); |
211 }); | 211 }); |
212 }); | 212 }); |
213 | 213 |
214 test("singleCompleteTimeoutCallbackThrowsFuture", () { | 214 test("TimeoutCallbackThrowsFuture", () { |
215 Completer completer = new Completer.sync(); | 215 Completer completer = new Completer.sync(); |
216 singleCompletePort(completer, | 216 singleCompletePort(completer, |
217 timeout: MS * 100, | 217 timeout: MS * 100, |
218 onTimeout: () => new Future.error(92)); | 218 onTimeout: () => new Future.error(92)); |
219 return completer.future.then((v) { | 219 return completer.future.then((v) { |
220 fail("unreachable"); | 220 fail("unreachable"); |
221 }, onError: (e, s) { | 221 }, onError: (e, s) { |
222 expect(e, 92); | 222 expect(e, 92); |
223 }); | 223 }); |
224 }); | 224 }); |
225 | 225 |
226 test("singleCompleteTimeoutCallbackSLow", () { | 226 test("TimeoutCallbackSLow", () { |
227 Completer completer = new Completer.sync(); | 227 Completer completer = new Completer.sync(); |
228 singleCompletePort( | 228 singleCompletePort( |
229 completer, | 229 completer, |
230 timeout: MS * 100, | 230 timeout: MS * 100, |
231 onTimeout: () => new Future.delayed(MS * 500, () => 87)); | 231 onTimeout: () => new Future.delayed(MS * 500, () => 87)); |
232 return completer.future.then((v) { | 232 return completer.future.then((v) { |
233 expect(v, 87); | 233 expect(v, 87); |
234 }); | 234 }); |
235 }); | 235 }); |
236 | 236 |
237 test("singleCompleteTimeoutCallbackThrowsSlow", () { | 237 test("TimeoutCallbackThrowsSlow", () { |
238 Completer completer = new Completer.sync(); | 238 Completer completer = new Completer.sync(); |
239 singleCompletePort( | 239 singleCompletePort( |
240 completer, | 240 completer, |
241 timeout: MS * 100, | 241 timeout: MS * 100, |
242 onTimeout: () => new Future.delayed(MS * 500, () => throw 87)); | 242 onTimeout: () => new Future.delayed(MS * 500, () => throw 87)); |
243 return completer.future.then((v) { | 243 return completer.future.then((v) { |
244 fail("unreachable"); | 244 fail("unreachable"); |
245 }, onError: (e, s) { | 245 }, onError: (e, s) { |
246 expect(e, 87); | 246 expect(e, 87); |
247 }); | 247 }); |
248 }); | 248 }); |
249 | 249 |
250 test("singleCompleteTimeoutFirst", () { | 250 test("TimeoutFirst", () { |
251 Completer completer = new Completer.sync(); | 251 Completer completer = new Completer.sync(); |
252 SendPort p = | 252 SendPort p = |
253 singleCompletePort(completer, timeout: MS * 100, onTimeout: () => 37); | 253 singleCompletePort(completer, timeout: MS * 100, onTimeout: () => 37); |
254 new Timer(MS * 500, () => p.send(42)); | 254 new Timer(MS * 500, () => p.send(42)); |
255 return completer.future.then((v) { | 255 return completer.future.then((v) { |
256 expect(v, 37); | 256 expect(v, 37); |
257 }); | 257 }); |
258 }); | 258 }); |
259 } | 259 } |
260 | 260 |
261 void testSingleResponseFuture() { | 261 void testSingleResponseFuture() { |
262 test("singleResponseFutureValue", () { | 262 test("FutureValue", () { |
263 return singleResponseFuture((SendPort p) { | 263 return singleResponseFuture((SendPort p) { |
264 p.send(42); | 264 p.send(42); |
265 }).then((v) { | 265 }).then((v) { |
266 expect(v, 42); | 266 expect(v, 42); |
267 }); | 267 }); |
268 }); | 268 }); |
269 | 269 |
270 test("singleResponseFutureValueFirst", () { | 270 test("FutureValueFirst", () { |
271 return singleResponseFuture((SendPort p) { | 271 return singleResponseFuture((SendPort p) { |
272 p.send(42); | 272 p.send(42); |
273 p.send(37); | 273 p.send(37); |
274 }).then((v) { | 274 }).then((v) { |
275 expect(v, 42); | 275 expect(v, 42); |
276 }); | 276 }); |
277 }); | 277 }); |
278 | 278 |
279 test("singleResponseFutureError", () { | 279 test("FutureError", () { |
280 return singleResponseFuture((SendPort p) { | 280 return singleResponseFuture((SendPort p) { |
281 throw 93; | 281 throw 93; |
282 }).then((v) { | 282 }).then((v) { |
283 fail("unreachable"); | 283 fail("unreachable"); |
284 }, onError: (e, s) { | 284 }, onError: (e, s) { |
285 expect(e, 93); | 285 expect(e, 93); |
286 }); | 286 }); |
287 }); | 287 }); |
288 | 288 |
289 test("singleResponseFutureTimeout", () { | 289 test("FutureTimeout", () { |
290 return singleResponseFuture((SendPort p) { | 290 return singleResponseFuture((SendPort p) { |
291 // no-op. | 291 // no-op. |
292 }, timeout: MS * 100).then((v) { | 292 }, timeout: MS * 100).then((v) { |
293 expect(v, null); | 293 expect(v, null); |
294 }); | 294 }); |
295 }); | 295 }); |
296 | 296 |
297 test("singleResponseFutureTimeoutValue", () { | 297 test("FutureTimeoutValue", () { |
298 return singleResponseFuture((SendPort p) { | 298 return singleResponseFuture((SendPort p) { |
299 // no-op. | 299 // no-op. |
300 }, timeout: MS * 100, timeoutValue: 42).then((v) { | 300 }, timeout: MS * 100, timeoutValue: 42).then((v) { |
301 expect(v, 42); | 301 expect(v, 42); |
302 }); | 302 }); |
303 }); | 303 }); |
304 } | 304 } |
305 | 305 |
306 void testSingleResultFuture() { | 306 void testSingleResultFuture() { |
307 test("singleResultFutureValue", () { | 307 test("Value", () { |
308 return singleResultFuture((SendPort p) { | 308 return singleResultFuture((SendPort p) { |
309 sendFutureResult(new Future.value(42), p); | 309 sendFutureResult(new Future.value(42), p); |
310 }).then((v) { | 310 }).then((v) { |
311 expect(v, 42); | 311 expect(v, 42); |
312 }); | 312 }); |
313 }); | 313 }); |
314 | 314 |
315 test("singleResultFutureValueFirst", () { | 315 test("ValueFirst", () { |
316 return singleResultFuture((SendPort p) { | 316 return singleResultFuture((SendPort p) { |
317 sendFutureResult(new Future.value(42), p); | 317 sendFutureResult(new Future.value(42), p); |
318 sendFutureResult(new Future.value(37), p); | 318 sendFutureResult(new Future.value(37), p); |
319 }).then((v) { | 319 }).then((v) { |
320 expect(v, 42); | 320 expect(v, 42); |
321 }); | 321 }); |
322 }); | 322 }); |
323 | 323 |
324 test("singleResultFutureError", () { | 324 test("Error", () { |
325 return singleResultFuture((SendPort p) { | 325 return singleResultFuture((SendPort p) { |
326 sendFutureResult(new Future.error(94), p); | 326 sendFutureResult(new Future.error(94), p); |
327 }).then((v) { | 327 }).then((v) { |
328 fail("unreachable"); | 328 fail("unreachable"); |
329 }, onError: (e, s) { | 329 }, onError: (e, s) { |
330 expect(e is RemoteError, isTrue); | 330 expect(e is RemoteError, isTrue); |
331 }); | 331 }); |
332 }); | 332 }); |
333 | 333 |
334 test("singleResultFutureErrorFirst", () { | 334 test("ErrorFirst", () { |
335 return singleResultFuture((SendPort p) { | 335 return singleResultFuture((SendPort p) { |
336 sendFutureResult(new Future.error(95), p); | 336 sendFutureResult(new Future.error(95), p); |
337 sendFutureResult(new Future.error(96), p); | 337 sendFutureResult(new Future.error(96), p); |
338 }).then((v) { | 338 }).then((v) { |
339 fail("unreachable"); | 339 fail("unreachable"); |
340 }, onError: (e, s) { | 340 }, onError: (e, s) { |
341 expect(e is RemoteError, isTrue); | 341 expect(e is RemoteError, isTrue); |
342 }); | 342 }); |
343 }); | 343 }); |
344 | 344 |
345 test("singleResultFutureError", () { | 345 test("Error", () { |
346 return singleResultFuture((SendPort p) { | 346 return singleResultFuture((SendPort p) { |
347 throw 93; | 347 throw 93; |
348 }).then((v) { | 348 }).then((v) { |
349 fail("unreachable"); | 349 fail("unreachable"); |
350 }, onError: (e, s) { | 350 }, onError: (e, s) { |
351 expect(e is RemoteError, isTrue); | 351 expect(e is RemoteError, isTrue); |
352 }); | 352 }); |
353 }); | 353 }); |
354 | 354 |
355 test("singleResultFutureTimeout", () { | 355 test("Timeout", () { |
356 return singleResultFuture((SendPort p) { | 356 return singleResultFuture((SendPort p) { |
357 // no-op. | 357 // no-op. |
358 }, timeout: MS * 100).then((v) { | 358 }, timeout: MS * 100).then((v) { |
359 fail("unreachable"); | 359 fail("unreachable"); |
360 }, onError: (e, s) { | 360 }, onError: (e, s) { |
361 expect(e is TimeoutException, isTrue); | 361 expect(e is TimeoutException, isTrue); |
362 }); | 362 }); |
363 }); | 363 }); |
364 | 364 |
365 test("singleResultFutureTimeoutValue", () { | 365 test("TimeoutValue", () { |
366 return singleResultFuture((SendPort p) { | 366 return singleResultFuture((SendPort p) { |
367 // no-op. | 367 // no-op. |
368 }, timeout: MS * 100, onTimeout: () => 42).then((v) { | 368 }, timeout: MS * 100, onTimeout: () => 42).then((v) { |
369 expect(v, 42); | 369 expect(v, 42); |
370 }); | 370 }); |
371 }); | 371 }); |
372 | 372 |
373 test("singleResultFutureTimeoutError", () { | 373 test("TimeoutError", () { |
374 return singleResultFuture((SendPort p) { | 374 return singleResultFuture((SendPort p) { |
375 // no-op. | 375 // no-op. |
376 }, timeout: MS * 100, onTimeout: () => throw 97).then((v) { | 376 }, timeout: MS * 100, onTimeout: () => throw 97).then((v) { |
377 expect(v, 42); | 377 expect(v, 42); |
378 }, onError: (e, s) { | 378 }, onError: (e, s) { |
379 expect(e, 97); | 379 expect(e, 97); |
380 }); | 380 }); |
381 }); | 381 }); |
382 } | 382 } |
383 | 383 |
384 void testSingleResponseChannel() { | 384 void testSingleResponseChannel() { |
385 test("singleResponseChannelValue", () { | 385 test("Value", () { |
386 var channel = new SingleResponseChannel(); | 386 var channel = new SingleResponseChannel(); |
387 channel.port.send(42); | 387 channel.port.send(42); |
388 return channel.result.then((v) { | 388 return channel.result.then((v) { |
389 expect(v, 42); | 389 expect(v, 42); |
390 }); | 390 }); |
391 }); | 391 }); |
392 | 392 |
393 test("singleResponseChannelValueFirst", () { | 393 test("ValueFirst", () { |
394 var channel = new SingleResponseChannel(); | 394 var channel = new SingleResponseChannel(); |
395 channel.port.send(42); | 395 channel.port.send(42); |
396 channel.port.send(37); | 396 channel.port.send(37); |
397 return channel.result.then((v) { | 397 return channel.result.then((v) { |
398 expect(v, 42); | 398 expect(v, 42); |
399 }); | 399 }); |
400 }); | 400 }); |
401 | 401 |
402 test("singleResponseChannelValueCallback", () { | 402 test("ValueCallback", () { |
403 var channel = new SingleResponseChannel(callback: (v) => v * 2); | 403 var channel = new SingleResponseChannel(callback: (v) => v * 2); |
404 channel.port.send(42); | 404 channel.port.send(42); |
405 return channel.result.then((v) { | 405 return channel.result.then((v) { |
406 expect(v, 84); | 406 expect(v, 84); |
407 }); | 407 }); |
408 }); | 408 }); |
409 | 409 |
410 test("singleResponseChannelErrorCallback", () { | 410 test("ErrorCallback", () { |
411 var channel = new SingleResponseChannel(callback: (v) => throw 42); | 411 var channel = new SingleResponseChannel(callback: (v) => throw 42); |
412 channel.port.send(37); | 412 channel.port.send(37); |
413 return channel.result.then((v) { fail("unreachable"); }, | 413 return channel.result.then((v) { fail("unreachable"); }, |
414 onError: (v, s) { | 414 onError: (v, s) { |
415 expect(v, 42); | 415 expect(v, 42); |
416 }); | 416 }); |
417 }); | 417 }); |
418 | 418 |
419 test("singleResponseChannelAsyncValueCallback", () { | 419 test("AsyncValueCallback", () { |
420 var channel = new SingleResponseChannel( | 420 var channel = new SingleResponseChannel( |
421 callback: (v) => new Future.value(v * 2)); | 421 callback: (v) => new Future.value(v * 2)); |
422 channel.port.send(42); | 422 channel.port.send(42); |
423 return channel.result.then((v) { | 423 return channel.result.then((v) { |
424 expect(v, 84); | 424 expect(v, 84); |
425 }); | 425 }); |
426 }); | 426 }); |
427 | 427 |
428 test("singleResponseChannelAsyncErrorCallback", () { | 428 test("AsyncErrorCallback", () { |
429 var channel = new SingleResponseChannel(callback: | 429 var channel = new SingleResponseChannel(callback: |
430 (v) => new Future.error(42)); | 430 (v) => new Future.error(42)); |
431 channel.port.send(37); | 431 channel.port.send(37); |
432 return channel.result.then((v) { fail("unreachable"); }, | 432 return channel.result.then((v) { fail("unreachable"); }, |
433 onError: (v, s) { | 433 onError: (v, s) { |
434 expect(v, 42); | 434 expect(v, 42); |
435 }); | 435 }); |
436 }); | 436 }); |
437 | 437 |
438 test("singleResponseChannelTimeout", () { | 438 test("Timeout", () { |
439 var channel = new SingleResponseChannel(timeout: MS * 100); | 439 var channel = new SingleResponseChannel(timeout: MS * 100); |
440 return channel.result.then((v) { | 440 return channel.result.then((v) { |
441 expect(v, null); | 441 expect(v, null); |
442 }); | 442 }); |
443 }); | 443 }); |
444 | 444 |
445 test("singleResponseChannelTimeoutThrow", () { | 445 test("TimeoutThrow", () { |
446 var channel = new SingleResponseChannel(timeout: MS * 100, | 446 var channel = new SingleResponseChannel(timeout: MS * 100, |
447 throwOnTimeout: true); | 447 throwOnTimeout: true); |
448 return channel.result.then((v) { fail("unreachable"); }, | 448 return channel.result.then((v) { fail("unreachable"); }, |
449 onError: (v, s) { | 449 onError: (v, s) { |
450 expect(v is TimeoutException, isTrue); | 450 expect(v is TimeoutException, isTrue); |
451 }); | 451 }); |
452 }); | 452 }); |
453 | 453 |
454 test("singleResponseChannelTimeoutThrowOnTimeoutAndValue", () { | 454 test("TimeoutThrowOnTimeoutAndValue", () { |
455 var channel = new SingleResponseChannel(timeout: MS * 100, | 455 var channel = new SingleResponseChannel(timeout: MS * 100, |
456 throwOnTimeout: true, | 456 throwOnTimeout: true, |
457 onTimeout: () => 42, | 457 onTimeout: () => 42, |
458 timeoutValue: 42); | 458 timeoutValue: 42); |
459 return channel.result.then((v) { fail("unreachable"); }, | 459 return channel.result.then((v) { fail("unreachable"); }, |
460 onError: (v, s) { | 460 onError: (v, s) { |
461 expect(v is TimeoutException, isTrue); | 461 expect(v is TimeoutException, isTrue); |
462 }); | 462 }); |
463 }); | 463 }); |
464 | 464 |
465 test("singleResponseChannelTimeoutOnTimeout", () { | 465 test("TimeoutOnTimeout", () { |
466 var channel = new SingleResponseChannel(timeout: MS * 100, | 466 var channel = new SingleResponseChannel(timeout: MS * 100, |
467 onTimeout: () => 42); | 467 onTimeout: () => 42); |
468 return channel.result.then((v) { | 468 return channel.result.then((v) { |
469 expect(v, 42); | 469 expect(v, 42); |
470 }); | 470 }); |
471 }); | 471 }); |
472 | 472 |
473 test("singleResponseChannelTimeoutOnTimeoutAndValue", () { | 473 test("TimeoutOnTimeoutAndValue", () { |
474 var channel = new SingleResponseChannel(timeout: MS * 100, | 474 var channel = new SingleResponseChannel(timeout: MS * 100, |
475 onTimeout: () => 42, | 475 onTimeout: () => 42, |
476 timeoutValue: 37); | 476 timeoutValue: 37); |
477 return channel.result.then((v) { | 477 return channel.result.then((v) { |
478 expect(v, 42); | 478 expect(v, 42); |
479 }); | 479 }); |
480 }); | 480 }); |
481 | 481 |
482 test("singleResponseChannelTimeoutValue", () { | 482 test("TimeoutValue", () { |
483 var channel = new SingleResponseChannel(timeout: MS * 100, | 483 var channel = new SingleResponseChannel(timeout: MS * 100, |
484 timeoutValue: 42); | 484 timeoutValue: 42); |
485 return channel.result.then((v) { | 485 return channel.result.then((v) { |
486 expect(v, 42); | 486 expect(v, 42); |
487 }); | 487 }); |
488 }); | 488 }); |
489 | 489 |
490 test("singleResponseChannelTimeoutOnTimeoutError", () { | 490 test("TimeoutOnTimeoutError", () { |
491 var channel = new SingleResponseChannel(timeout: MS * 100, | 491 var channel = new SingleResponseChannel(timeout: MS * 100, |
492 onTimeout: () => throw 42); | 492 onTimeout: () => throw 42); |
493 return channel.result.then((v) { fail("unreachable"); }, | 493 return channel.result.then((v) { fail("unreachable"); }, |
494 onError: (v, s) { | 494 onError: (v, s) { |
495 expect(v, 42); | 495 expect(v, 42); |
496 }); | 496 }); |
497 }); | 497 }); |
498 | 498 |
499 test("singleResponseChannelTimeoutOnTimeoutAsync", () { | 499 test("TimeoutOnTimeoutAsync", () { |
500 var channel = new SingleResponseChannel(timeout: MS * 100, | 500 var channel = new SingleResponseChannel(timeout: MS * 100, |
501 onTimeout: | 501 onTimeout: |
502 () => new Future.value(42)); | 502 () => new Future.value(42)); |
503 return channel.result.then((v) { | 503 return channel.result.then((v) { |
504 expect(v, 42); | 504 expect(v, 42); |
505 }); | 505 }); |
506 }); | 506 }); |
507 | 507 |
508 test("singleResponseChannelTimeoutOnTimeoutAsyncError", () { | 508 test("TimeoutOnTimeoutAsyncError", () { |
509 var channel = new SingleResponseChannel(timeout: MS * 100, | 509 var channel = new SingleResponseChannel(timeout: MS * 100, |
510 onTimeout: | 510 onTimeout: |
511 () => new Future.error(42)); | 511 () => new Future.error(42)); |
512 return channel.result.then((v) { fail("unreachable"); }, | 512 return channel.result.then((v) { fail("unreachable"); }, |
513 onError: (v, s) { | 513 onError: (v, s) { |
514 expect(v, 42); | 514 expect(v, 42); |
515 }); | 515 }); |
516 }); | 516 }); |
517 } | 517 } |
OLD | NEW |