OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
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. | |
4 | |
5 library scheduled_test_test; | |
6 | |
7 import 'dart:async'; | |
8 import 'dart:io'; | |
9 | |
10 import 'package:scheduled_test/scheduled_test.dart'; | |
11 import 'package:scheduled_test/src/mock_clock.dart' as mock_clock; | |
12 | |
13 import 'metatest.dart'; | |
14 import 'utils.dart'; | |
15 | |
16 void main() { | |
17 metaSetUp(() { | |
18 // TODO(nweiz): We used to only increase the timeout to 10s for the Windows | |
19 // bots, but the Linux and Mac bots have started taking upwards of 5s when | |
20 // running pumpEventQueue, so we're increasing the timeout across the board | |
21 // (see issue 9248). | |
22 currentSchedule.timeout = new Duration(seconds: 10); | |
23 }); | |
24 | |
25 expectTestsPass('a scheduled test with a correct synchronous expectation ' | |
26 'should pass', () { | |
27 test('test', () { | |
28 expect('foo', equals('foo')); | |
29 }); | |
30 }); | |
31 | |
32 expectTestsFail('a scheduled test with an incorrect synchronous expectation ' | |
33 'should fail', () { | |
34 test('test', () { | |
35 expect('foo', equals('bar')); | |
36 }); | |
37 }); | |
38 | |
39 expectTestsPass('a scheduled test with a correct asynchronous expectation ' | |
40 'should pass', () { | |
41 test('test', () { | |
42 expect(new Future.immediate('foo'), completion(equals('foo'))); | |
43 }); | |
44 }); | |
45 | |
46 expectTestsFail('a scheduled test with an incorrect asynchronous expectation ' | |
47 'should fail', () { | |
48 test('test', () { | |
49 expect(new Future.immediate('foo'), completion(equals('bar'))); | |
50 }); | |
51 }); | |
52 | |
53 expectTestsPass('a passing scheduled synchronous expect should register', () { | |
54 test('test', () { | |
55 schedule(() => expect('foo', equals('foo'))); | |
56 }); | |
57 }); | |
58 | |
59 expectTestsFail('a failing scheduled synchronous expect should register', () { | |
60 test('test', () { | |
61 schedule(() => expect('foo', equals('bar'))); | |
62 }); | |
63 }); | |
64 | |
65 expectTestsPass('a passing scheduled asynchronous expect should ' | |
66 'register', () { | |
67 test('test', () { | |
68 schedule(() => | |
69 expect(new Future.immediate('foo'), completion(equals('foo')))); | |
70 }); | |
71 }); | |
72 | |
73 expectTestsFail('a failing scheduled synchronous expect should ' | |
74 'register', () { | |
75 test('test', () { | |
76 schedule(() => | |
77 expect(new Future.immediate('foo'), completion(equals('bar')))); | |
78 }); | |
79 }); | |
80 | |
81 expectTestsPass('scheduled blocks should be run in order after the ' | |
82 'synchronous setup', () { | |
83 test('test', () { | |
84 var list = [1]; | |
85 schedule(() => list.add(2)); | |
86 list.add(3); | |
87 schedule(() => expect(list, equals([1, 3, 4, 2]))); | |
88 list.add(4); | |
89 }); | |
90 }); | |
91 | |
92 expectTestsPass('scheduled blocks should forward their return values as ' | |
93 'Futures', () { | |
94 test('synchronous value', () { | |
95 var future = schedule(() => 'value'); | |
96 expect(future, completion(equals('value'))); | |
97 }); | |
98 | |
99 test('asynchronous value', () { | |
100 var future = schedule(() => new Future.immediate('value')); | |
101 expect(future, completion(equals('value'))); | |
102 }); | |
103 }); | |
104 | |
105 expectTestsPass('scheduled blocks should wait for their Future return values ' | |
106 'to complete before proceeding', () { | |
107 test('test', () { | |
108 var value = 'unset'; | |
109 schedule(() => pumpEventQueue().then((_) { | |
110 value = 'set'; | |
111 })); | |
112 schedule(() => expect(value, equals('set'))); | |
113 }); | |
114 }); | |
115 | |
116 expectTestsFail('a test failure in a chained future in a scheduled block ' | |
117 'should be registered', () { | |
118 test('test', () { | |
119 schedule(() => new Future.immediate('foo') | |
120 .then((v) => expect(v, equals('bar')))); | |
121 }); | |
122 }); | |
123 | |
124 expectTestsFail('an error in a chained future in a scheduled block should be ' | |
125 'registered', () { | |
126 test('test', () { | |
127 schedule(() => new Future.immediate(null).then((_) { | |
128 throw 'error'; | |
129 })); | |
130 }); | |
131 }); | |
132 | |
133 expectTestsFail('an out-of-band failure in wrapAsync is handled', () { | |
134 mock_clock.mock().run(); | |
135 test('test', () { | |
136 schedule(() { | |
137 sleep(1).then(wrapAsync((_) => expect('foo', equals('bar')))); | |
138 }); | |
139 schedule(() => sleep(2)); | |
140 }); | |
141 }); | |
142 | |
143 expectTestsFail('an out-of-band failure in wrapAsync that finishes after the ' | |
144 'schedule is handled', () { | |
145 mock_clock.mock().run(); | |
146 test('test', () { | |
147 schedule(() { | |
148 sleep(2).then(wrapAsync((_) => expect('foo', equals('bar')))); | |
149 }); | |
150 schedule(() => sleep(1)); | |
151 }); | |
152 }); | |
153 | |
154 expectTestsFail('an out-of-band failure in wrapFuture is handled', () { | |
155 mock_clock.mock().run(); | |
156 test('test', () { | |
157 schedule(() { | |
158 wrapFuture(sleep(1).then((_) => expect('foo', equals('bar')))); | |
159 }); | |
160 schedule(() => sleep(2)); | |
161 }); | |
162 }); | |
163 | |
164 expectTestsFail('an out-of-band failure in wrapFuture that finishes after ' | |
165 'the schedule is handled', () { | |
166 mock_clock.mock().run(); | |
167 test('test', () { | |
168 schedule(() { | |
169 wrapFuture(sleep(2).then((_) => expect('foo', equals('bar')))); | |
170 }); | |
171 schedule(() => sleep(1)); | |
172 }); | |
173 }); | |
174 | |
175 expectTestsPass("wrapFuture should return the value of the wrapped future", | |
176 () { | |
177 test('test', () { | |
178 schedule(() { | |
179 expect(wrapFuture(pumpEventQueue().then((_) => 'foo')), | |
180 completion(equals('foo'))); | |
181 }); | |
182 }); | |
183 }); | |
184 | |
185 expectTestsPass("wrapFuture should pass through the error of the wrapped " | |
186 "future", () { | |
187 var error; | |
188 test('test 1', () { | |
189 schedule(() { | |
190 wrapFuture(pumpEventQueue().then((_) { | |
191 throw 'error'; | |
192 })).catchError(wrapAsync((e) { | |
193 error = e.error; | |
194 })); | |
195 }); | |
196 }); | |
197 | |
198 test('test 2', () { | |
199 expect(error, equals('error')); | |
200 }); | |
201 }, passing: ['test 2']); | |
202 | |
203 expectTestsPass("scheduled blocks whose return values are passed to " | |
204 "wrapFuture should report exceptions once", () { | |
205 var errors; | |
206 test('test 1', () { | |
207 currentSchedule.onException.schedule(() { | |
208 errors = currentSchedule.errors; | |
209 }); | |
210 | |
211 wrapFuture(schedule(() { | |
212 throw 'error'; | |
213 })); | |
214 }); | |
215 | |
216 test('test 2', () { | |
217 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
218 expect(errors.map((e) => e.error), equals(['error'])); | |
219 }); | |
220 }, passing: ['test 2']); | |
221 | |
222 expectTestsFail('an out-of-band error reported via signalError is ' | |
223 'handled', () { | |
224 mock_clock.mock().run(); | |
225 test('test', () { | |
226 schedule(() { | |
227 sleep(1).then((_) => currentSchedule.signalError('bad')); | |
228 }); | |
229 schedule(() => sleep(2)); | |
230 }); | |
231 }); | |
232 | |
233 expectTestsFail('an out-of-band error reported via signalError that finished ' | |
234 'after the schedule is handled', () { | |
235 mock_clock.mock().run(); | |
236 test('test', () { | |
237 schedule(() { | |
238 var done = wrapAsync((_) {}); | |
239 sleep(2).then((_) { | |
240 currentSchedule.signalError('bad'); | |
241 done(null); | |
242 }); | |
243 }); | |
244 schedule(() => sleep(1)); | |
245 }); | |
246 }); | |
247 | |
248 expectTestsFail('a synchronous error reported via signalError is handled', ()
{ | |
249 test('test', () { | |
250 currentSchedule.signalError('bad'); | |
251 }); | |
252 }); | |
253 | |
254 expectTestsPass('the onComplete queue is run if a test is successful', () { | |
255 var onCompleteRun = false; | |
256 test('test 1', () { | |
257 currentSchedule.onComplete.schedule(() { | |
258 onCompleteRun = true; | |
259 }); | |
260 | |
261 schedule(() => expect('foo', equals('foo'))); | |
262 }); | |
263 | |
264 test('test 2', () { | |
265 expect(onCompleteRun, isTrue); | |
266 }); | |
267 }); | |
268 | |
269 expectTestsPass('the onComplete queue is run after an out-of-band callback', | |
270 () { | |
271 var outOfBandRun = false; | |
272 test('test1', () { | |
273 currentSchedule.onComplete.schedule(() { | |
274 expect(outOfBandRun, isTrue); | |
275 }); | |
276 | |
277 pumpEventQueue().then(wrapAsync((_) { | |
278 outOfBandRun = true; | |
279 })); | |
280 }); | |
281 }); | |
282 | |
283 expectTestsPass('the onComplete queue is run after an out-of-band callback ' | |
284 'and waits for another out-of-band callback', () { | |
285 var outOfBand1Run = false; | |
286 var outOfBand2Run = false; | |
287 test('test1', () { | |
288 currentSchedule.onComplete.schedule(() { | |
289 expect(outOfBand1Run, isTrue); | |
290 | |
291 pumpEventQueue().then(wrapAsync((_) { | |
292 outOfBand2Run = true; | |
293 })); | |
294 }); | |
295 | |
296 pumpEventQueue().then(wrapAsync((_) { | |
297 outOfBand1Run = true; | |
298 })); | |
299 }); | |
300 | |
301 test('test2', () => expect(outOfBand2Run, isTrue)); | |
302 }); | |
303 | |
304 expectTestsFail('an out-of-band callback in the onComplete queue blocks the ' | |
305 'test', () { | |
306 test('test', () { | |
307 currentSchedule.onComplete.schedule(() { | |
308 pumpEventQueue().then(wrapAsync((_) => expect('foo', equals('bar')))); | |
309 }); | |
310 }); | |
311 }); | |
312 | |
313 expectTestsPass('an out-of-band callback blocks onComplete even with an ' | |
314 'unrelated error', () { | |
315 var outOfBandRun = false; | |
316 var outOfBandSetInOnComplete = false; | |
317 test('test 1', () { | |
318 currentSchedule.onComplete.schedule(() { | |
319 outOfBandSetInOnComplete = outOfBandRun; | |
320 }); | |
321 | |
322 pumpEventQueue().then(wrapAsync((_) { | |
323 outOfBandRun = true; | |
324 })); | |
325 | |
326 schedule(() => expect('foo', equals('bar'))); | |
327 }); | |
328 | |
329 test('test 2', () => expect(outOfBandSetInOnComplete, isTrue)); | |
330 }, passing: ['test 2']); | |
331 | |
332 expectTestsPass('the onComplete queue is run after an asynchronous error', | |
333 () { | |
334 var onCompleteRun = false; | |
335 test('test 1', () { | |
336 currentSchedule.onComplete.schedule(() { | |
337 onCompleteRun = true; | |
338 }); | |
339 | |
340 schedule(() => expect('foo', equals('bar'))); | |
341 }); | |
342 | |
343 test('test 2', () { | |
344 expect(onCompleteRun, isTrue); | |
345 }); | |
346 }, passing: ['test 2']); | |
347 | |
348 expectTestsPass('the onComplete queue is run after a synchronous error', () { | |
349 var onCompleteRun = false; | |
350 test('test 1', () { | |
351 currentSchedule.onComplete.schedule(() { | |
352 onCompleteRun = true; | |
353 }); | |
354 | |
355 throw 'error'; | |
356 }); | |
357 | |
358 test('test 2', () { | |
359 expect(onCompleteRun, isTrue); | |
360 }); | |
361 }, passing: ['test 2']); | |
362 | |
363 expectTestsPass('the onComplete queue is run after an out-of-band error', () { | |
364 var onCompleteRun = false; | |
365 test('test 1', () { | |
366 currentSchedule.onComplete.schedule(() { | |
367 onCompleteRun = true; | |
368 }); | |
369 | |
370 pumpEventQueue().then(wrapAsync((_) => expect('foo', equals('bar')))); | |
371 }); | |
372 | |
373 test('test 2', () { | |
374 expect(onCompleteRun, isTrue); | |
375 }); | |
376 }, passing: ['test 2']); | |
377 | |
378 expectTestsPass('currentSchedule.errors contains the error in the onComplete ' | |
379 'queue', () { | |
380 var errors; | |
381 test('test 1', () { | |
382 currentSchedule.onComplete.schedule(() { | |
383 errors = currentSchedule.errors; | |
384 }); | |
385 | |
386 throw 'error'; | |
387 }); | |
388 | |
389 test('test 2', () { | |
390 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
391 expect(errors.map((e) => e.error), equals(['error'])); | |
392 }); | |
393 }, passing: ['test 2']); | |
394 | |
395 expectTestsPass('onComplete tasks can be scheduled during normal tasks', () { | |
396 var onCompleteRun = false; | |
397 test('test 1', () { | |
398 schedule(() { | |
399 currentSchedule.onComplete.schedule(() { | |
400 onCompleteRun = true; | |
401 }); | |
402 }); | |
403 }); | |
404 | |
405 test('test 2', () { | |
406 expect(onCompleteRun, isTrue); | |
407 }); | |
408 }); | |
409 | |
410 expectTestsFail('failures in onComplete cause test failures', () { | |
411 test('test', () { | |
412 currentSchedule.onComplete.schedule(() { | |
413 expect('foo', equals('bar')); | |
414 }); | |
415 }); | |
416 }); | |
417 | |
418 expectTestsPass('the onException queue is not run if a test is successful', | |
419 () { | |
420 var onExceptionRun = false; | |
421 test('test 1', () { | |
422 currentSchedule.onException.schedule(() { | |
423 onExceptionRun = true; | |
424 }); | |
425 | |
426 schedule(() => expect('foo', equals('foo'))); | |
427 }); | |
428 | |
429 test('test 2', () { | |
430 expect(onExceptionRun, isFalse); | |
431 }); | |
432 }); | |
433 | |
434 expectTestsPass('the onException queue is run after an asynchronous error', | |
435 () { | |
436 var onExceptionRun = false; | |
437 test('test 1', () { | |
438 currentSchedule.onException.schedule(() { | |
439 onExceptionRun = true; | |
440 }); | |
441 | |
442 schedule(() => expect('foo', equals('bar'))); | |
443 }); | |
444 | |
445 test('test 2', () { | |
446 expect(onExceptionRun, isTrue); | |
447 }); | |
448 }, passing: ['test 2']); | |
449 | |
450 expectTestsPass('the onException queue is run after a synchronous error', () { | |
451 var onExceptionRun = false; | |
452 test('test 1', () { | |
453 currentSchedule.onException.schedule(() { | |
454 onExceptionRun = true; | |
455 }); | |
456 | |
457 throw 'error'; | |
458 }); | |
459 | |
460 test('test 2', () { | |
461 expect(onExceptionRun, isTrue); | |
462 }); | |
463 }, passing: ['test 2']); | |
464 | |
465 expectTestsPass('the onException queue is run after an out-of-band error', ()
{ | |
466 var onExceptionRun = false; | |
467 test('test 1', () { | |
468 currentSchedule.onException.schedule(() { | |
469 onExceptionRun = true; | |
470 }); | |
471 | |
472 pumpEventQueue().then(wrapAsync((_) => expect('foo', equals('bar')))); | |
473 }); | |
474 | |
475 test('test 2', () { | |
476 expect(onExceptionRun, isTrue); | |
477 }); | |
478 }, passing: ['test 2']); | |
479 | |
480 expectTestsPass('currentSchedule.errors contains the error in the ' | |
481 'onException queue', () { | |
482 var errors; | |
483 test('test 1', () { | |
484 currentSchedule.onException.schedule(() { | |
485 errors = currentSchedule.errors; | |
486 }); | |
487 | |
488 throw 'error'; | |
489 }); | |
490 | |
491 test('test 2', () { | |
492 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
493 expect(errors.map((e) => e.error), equals(['error'])); | |
494 }); | |
495 }, passing: ['test 2']); | |
496 | |
497 expectTestsPass('currentSchedule.errors contains an error passed into ' | |
498 'signalError synchronously', () { | |
499 var errors; | |
500 test('test 1', () { | |
501 currentSchedule.onException.schedule(() { | |
502 errors = currentSchedule.errors; | |
503 }); | |
504 | |
505 currentSchedule.signalError('error'); | |
506 }); | |
507 | |
508 test('test 2', () { | |
509 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
510 expect(errors.map((e) => e.error), equals(['error'])); | |
511 }); | |
512 }, passing: ['test 2']); | |
513 | |
514 expectTestsPass('currentSchedule.errors contains an error passed into ' | |
515 'signalError asynchronously', () { | |
516 var errors; | |
517 test('test 1', () { | |
518 currentSchedule.onException.schedule(() { | |
519 errors = currentSchedule.errors; | |
520 }); | |
521 | |
522 schedule(() => currentSchedule.signalError('error')); | |
523 }); | |
524 | |
525 test('test 2', () { | |
526 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
527 expect(errors.map((e) => e.error), equals(['error'])); | |
528 }); | |
529 }, passing: ['test 2']); | |
530 | |
531 expectTestsPass('currentSchedule.errors contains an error passed into ' | |
532 'signalError out-of-band', () { | |
533 var errors; | |
534 test('test 1', () { | |
535 currentSchedule.onException.schedule(() { | |
536 errors = currentSchedule.errors; | |
537 }); | |
538 | |
539 pumpEventQueue().then(wrapAsync((_) { | |
540 return currentSchedule.signalError('error'); | |
541 })); | |
542 }); | |
543 | |
544 test('test 2', () { | |
545 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
546 expect(errors.map((e) => e.error), equals(['error'])); | |
547 }); | |
548 }, passing: ['test 2']); | |
549 | |
550 expectTestsPass('currentSchedule.errors contains errors from both the task ' | |
551 'queue and the onException queue in onComplete', () { | |
552 var errors; | |
553 test('test 1', () { | |
554 currentSchedule.onComplete.schedule(() { | |
555 errors = currentSchedule.errors; | |
556 }); | |
557 | |
558 currentSchedule.onException.schedule(() { | |
559 throw 'error2'; | |
560 }); | |
561 | |
562 throw 'error1'; | |
563 }); | |
564 | |
565 test('test 2', () { | |
566 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
567 expect(errors.map((e) => e.error), equals(['error1', 'error2'])); | |
568 }); | |
569 }, passing: ['test 2']); | |
570 | |
571 expectTestsPass('currentSchedule.errors contains multiple out-of-band errors ' | |
572 'from both the main task queue and onException in onComplete', () { | |
573 mock_clock.mock().run(); | |
574 var errors; | |
575 test('test 1', () { | |
576 currentSchedule.onComplete.schedule(() { | |
577 errors = currentSchedule.errors; | |
578 }); | |
579 | |
580 currentSchedule.onException.schedule(() { | |
581 sleep(1).then(wrapAsync((_) { | |
582 throw 'error3'; | |
583 })); | |
584 sleep(2).then(wrapAsync((_) { | |
585 throw 'error4'; | |
586 })); | |
587 }); | |
588 | |
589 sleep(1).then(wrapAsync((_) { | |
590 throw 'error1'; | |
591 })); | |
592 sleep(2).then(wrapAsync((_) { | |
593 throw 'error2'; | |
594 })); | |
595 }); | |
596 | |
597 test('test 2', () { | |
598 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
599 expect(errors.map((e) => e.error), | |
600 orderedEquals(['error1', 'error2', 'error3', 'error4'])); | |
601 }); | |
602 }, passing: ['test 2']); | |
603 | |
604 expectTestsPass('currentSchedule.errors contains multiple out-of-band errors ' | |
605 'from both the main task queue and onException in onComplete reported ' | |
606 'via wrapFuture', () { | |
607 mock_clock.mock().run(); | |
608 var errors; | |
609 test('test 1', () { | |
610 currentSchedule.onComplete.schedule(() { | |
611 errors = currentSchedule.errors; | |
612 }); | |
613 | |
614 currentSchedule.onException.schedule(() { | |
615 wrapFuture(sleep(1).then((_) { | |
616 throw 'error3'; | |
617 })); | |
618 wrapFuture(sleep(2).then((_) { | |
619 throw 'error4'; | |
620 })); | |
621 }); | |
622 | |
623 wrapFuture(sleep(1).then((_) { | |
624 throw 'error1'; | |
625 })); | |
626 wrapFuture(sleep(2).then((_) { | |
627 throw 'error2'; | |
628 })); | |
629 }); | |
630 | |
631 test('test 2', () { | |
632 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
633 expect(errors.map((e) => e.error), | |
634 orderedEquals(['error1', 'error2', 'error3', 'error4'])); | |
635 }); | |
636 }, passing: ['test 2']); | |
637 | |
638 expectTestsPass('currentSchedule.errors contains both an out-of-band error ' | |
639 'and an error raised afterwards in a task', () { | |
640 mock_clock.mock().run(); | |
641 var errors; | |
642 test('test 1', () { | |
643 currentSchedule.onComplete.schedule(() { | |
644 errors = currentSchedule.errors; | |
645 }); | |
646 | |
647 sleep(1).then(wrapAsync((_) { | |
648 throw 'out-of-band'; | |
649 })); | |
650 | |
651 schedule(() => sleep(2).then((_) { | |
652 throw 'in-band'; | |
653 })); | |
654 }); | |
655 | |
656 test('test 2', () { | |
657 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
658 expect(errors.map((e) => e.error), equals(['out-of-band', 'in-band'])); | |
659 }); | |
660 }, passing: ['test 2']); | |
661 | |
662 expectTestsPass('currentSchedule.errors contains both an error raised in a ' | |
663 'task and an error raised afterwards out-of-band', () { | |
664 mock_clock.mock().run(); | |
665 var errors; | |
666 test('test 1', () { | |
667 currentSchedule.onComplete.schedule(() { | |
668 errors = currentSchedule.errors; | |
669 }); | |
670 | |
671 sleep(2).then(wrapAsync((_) { | |
672 throw 'out-of-band'; | |
673 })); | |
674 | |
675 schedule(() => sleep(1).then((_) { | |
676 throw 'in-band'; | |
677 })); | |
678 }); | |
679 | |
680 test('test 2', () { | |
681 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
682 expect(errors.map((e) => e.error), equals(['in-band', 'out-of-band'])); | |
683 }); | |
684 }, passing: ['test 2']); | |
685 | |
686 expectTestsPass('currentSchedule.currentTask returns the current task while ' | |
687 'executing a task', () { | |
688 test('test', () { | |
689 schedule(() => expect('foo', equals('foo')), 'task 1'); | |
690 | |
691 schedule(() { | |
692 expect(currentSchedule.currentTask.description, equals('task 2')); | |
693 }, 'task 2'); | |
694 | |
695 schedule(() => expect('bar', equals('bar')), 'task 3'); | |
696 }); | |
697 }); | |
698 | |
699 expectTestsPass('currentSchedule.currentTask is null before the schedule has ' | |
700 'started', () { | |
701 test('test', () { | |
702 schedule(() => expect('foo', equals('foo'))); | |
703 | |
704 expect(currentSchedule.currentTask, isNull); | |
705 }); | |
706 }); | |
707 | |
708 expectTestsPass('currentSchedule.currentTask is null after the schedule has ' | |
709 'completed', () { | |
710 test('test', () { | |
711 schedule(() { | |
712 expect(pumpEventQueue().then((_) { | |
713 expect(currentSchedule.currentTask, isNull); | |
714 }), completes); | |
715 }); | |
716 | |
717 schedule(() => expect('foo', equals('foo'))); | |
718 }); | |
719 }); | |
720 | |
721 expectTestsPass('currentSchedule.currentQueue returns the current queue while
' | |
722 'executing a task', () { | |
723 test('test', () { | |
724 schedule(() { | |
725 expect(currentSchedule.currentQueue.name, equals('tasks')); | |
726 }); | |
727 }); | |
728 }); | |
729 | |
730 expectTestsPass('currentSchedule.currentQueue is tasks before the schedule ' | |
731 'has started', () { | |
732 test('test', () { | |
733 schedule(() => expect('foo', equals('foo'))); | |
734 | |
735 expect(currentSchedule.currentQueue.name, equals('tasks')); | |
736 }); | |
737 }); | |
738 | |
739 expectTestsPass('currentSchedule.state starts out as SET_UP', () { | |
740 test('test', () { | |
741 expect(currentSchedule.state, equals(ScheduleState.SET_UP)); | |
742 }); | |
743 }); | |
744 | |
745 expectTestsPass('currentSchedule.state is RUNNING in tasks', () { | |
746 test('test', () { | |
747 schedule(() { | |
748 expect(currentSchedule.state, equals(ScheduleState.RUNNING)); | |
749 }); | |
750 | |
751 currentSchedule.onComplete.schedule(() { | |
752 expect(currentSchedule.state, equals(ScheduleState.RUNNING)); | |
753 }); | |
754 }); | |
755 }); | |
756 | |
757 expectTestsPass('currentSchedule.state is DONE after the test', () { | |
758 var oldSchedule; | |
759 test('test 1', () { | |
760 oldSchedule = currentSchedule; | |
761 }); | |
762 | |
763 test('test 2', () { | |
764 expect(oldSchedule.state, equals(ScheduleState.DONE)); | |
765 }); | |
766 }); | |
767 | |
768 expectTestsPass('setUp is run before each test', () { | |
769 var setUpRun = false; | |
770 setUp(() { | |
771 setUpRun = true; | |
772 }); | |
773 | |
774 test('test 1', () { | |
775 expect(setUpRun, isTrue); | |
776 setUpRun = false; | |
777 }); | |
778 | |
779 test('test 2', () { | |
780 expect(setUpRun, isTrue); | |
781 setUpRun = false; | |
782 }); | |
783 }); | |
784 | |
785 expectTestsPass('setUp can schedule events', () { | |
786 var setUpRun = false; | |
787 setUp(() { | |
788 schedule(() { | |
789 setUpRun = true; | |
790 }); | |
791 currentSchedule.onComplete.schedule(() { | |
792 setUpRun = false; | |
793 }); | |
794 }); | |
795 | |
796 test('test 1', () { | |
797 expect(setUpRun, isFalse); | |
798 schedule(() => expect(setUpRun, isTrue)); | |
799 }); | |
800 | |
801 test('test 2', () { | |
802 expect(setUpRun, isFalse); | |
803 schedule(() => expect(setUpRun, isTrue)); | |
804 }); | |
805 }); | |
806 | |
807 expectTestsFail('synchronous errors in setUp will cause tests to fail', () { | |
808 setUp(() => expect('foo', equals('bar'))); | |
809 test('test 1', () => expect('foo', equals('foo'))); | |
810 test('test 2', () => expect('foo', equals('foo'))); | |
811 }); | |
812 | |
813 expectTestsFail('scheduled errors in setUp will cause tests to fail', () { | |
814 setUp(() => schedule(() => expect('foo', equals('bar')))); | |
815 test('test 1', () => expect('foo', equals('foo'))); | |
816 test('test 2', () => expect('foo', equals('foo'))); | |
817 }); | |
818 | |
819 expectTestsPass('synchronous errors in setUp will cause onException to run', | |
820 () { | |
821 var onExceptionRun = false; | |
822 setUp(() { | |
823 currentSchedule.onException.schedule(() { | |
824 onExceptionRun = true; | |
825 }); | |
826 | |
827 if (!onExceptionRun) expect('foo', equals('bar')); | |
828 }); | |
829 | |
830 test('test 1', () => expect('foo', equals('foo'))); | |
831 test('test 2', () => expect(onExceptionRun, isTrue)); | |
832 }, passing: ['test 2']); | |
833 | |
834 expectTestsPass("setUp doesn't apply to child groups", () { | |
835 var setUpRun = false; | |
836 setUp(() { | |
837 setUpRun = true; | |
838 currentSchedule.onComplete.schedule(() { | |
839 setUpRun = false; | |
840 }); | |
841 }); | |
842 | |
843 test('outer', () { | |
844 expect(setUpRun, isTrue); | |
845 }); | |
846 | |
847 group('group', () { | |
848 test('inner', () { | |
849 expect(setUpRun, isFalse); | |
850 }); | |
851 }); | |
852 }); | |
853 | |
854 expectTestsPass("setUp doesn't apply to parent groups", () { | |
855 var setUpRun = false; | |
856 group('group', () { | |
857 setUp(() { | |
858 setUpRun = true; | |
859 currentSchedule.onComplete.schedule(() { | |
860 setUpRun = false; | |
861 }); | |
862 }); | |
863 | |
864 test('inner', () { | |
865 expect(setUpRun, isTrue); | |
866 }); | |
867 }); | |
868 | |
869 test('outer', () { | |
870 expect(setUpRun, isFalse); | |
871 }); | |
872 }); | |
873 | |
874 expectTestsPass("setUp doesn't apply to sibling groups", () { | |
875 var setUpRun = false; | |
876 group('group 1', () { | |
877 setUp(() { | |
878 setUpRun = true; | |
879 currentSchedule.onComplete.schedule(() { | |
880 setUpRun = false; | |
881 }); | |
882 }); | |
883 | |
884 test('test 1', () { | |
885 expect(setUpRun, isTrue); | |
886 }); | |
887 }); | |
888 | |
889 group('group 2', () { | |
890 test('test 2', () { | |
891 expect(setUpRun, isFalse); | |
892 }); | |
893 }); | |
894 }); | |
895 | |
896 expectTestsPass("a single task that takes too long will cause a timeout " | |
897 "error", () { | |
898 mock_clock.mock().run(); | |
899 var errors; | |
900 test('test 1', () { | |
901 currentSchedule.timeout = new Duration(milliseconds: 1); | |
902 | |
903 currentSchedule.onException.schedule(() { | |
904 errors = currentSchedule.errors; | |
905 }); | |
906 | |
907 schedule(() => sleep(2)); | |
908 }); | |
909 | |
910 test('test 2', () { | |
911 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
912 expect(errors.map((e) => e.error), equals(["The schedule timed out after " | |
913 "0:00:00.001000 of inactivity."])); | |
914 }); | |
915 }, passing: ['test 2']); | |
916 | |
917 expectTestsPass("an out-of-band callback that takes too long will cause a " | |
918 "timeout error", () { | |
919 mock_clock.mock().run(); | |
920 var errors; | |
921 test('test 1', () { | |
922 currentSchedule.timeout = new Duration(milliseconds: 1); | |
923 | |
924 currentSchedule.onException.schedule(() { | |
925 errors = currentSchedule.errors; | |
926 }); | |
927 | |
928 sleep(2).then(wrapAsync((_) => expect('foo', equals('foo')))); | |
929 }); | |
930 | |
931 test('test 2', () { | |
932 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
933 expect(errors.map((e) => e.error), equals(["The schedule timed out after " | |
934 "0:00:00.001000 of inactivity."])); | |
935 }); | |
936 }, passing: ['test 2']); | |
937 | |
938 expectTestsPass("each task resets the timeout timer", () { | |
939 mock_clock.mock().run(); | |
940 test('test', () { | |
941 currentSchedule.timeout = new Duration(milliseconds: 2); | |
942 | |
943 schedule(() => sleep(1)); | |
944 schedule(() => sleep(1)); | |
945 schedule(() => sleep(1)); | |
946 }); | |
947 }); | |
948 | |
949 expectTestsPass("setting up the test doesn't trigger a timeout", () { | |
950 var clock = mock_clock.mock(); | |
951 test('test', () { | |
952 currentSchedule.timeout = new Duration(milliseconds: 1); | |
953 | |
954 clock.tick(2); | |
955 schedule(() => expect('foo', equals('foo'))); | |
956 }); | |
957 }); | |
958 | |
959 expectTestsPass("an out-of-band error that's signaled after a timeout but " | |
960 "before the test completes is registered", () { | |
961 mock_clock.mock().run(); | |
962 var errors; | |
963 test('test 1', () { | |
964 currentSchedule.timeout = new Duration(milliseconds: 3); | |
965 | |
966 currentSchedule.onException.schedule(() => sleep(2)); | |
967 currentSchedule.onException.schedule(() { | |
968 errors = currentSchedule.errors; | |
969 }); | |
970 | |
971 sleep(4).then(wrapAsync((_) { | |
972 throw 'out-of-band'; | |
973 })); | |
974 }); | |
975 | |
976 test('test 2', () { | |
977 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
978 expect(errors.map((e) => e.error), equals([ | |
979 "The schedule timed out after 0:00:00.003000 of inactivity.", | |
980 "out-of-band" | |
981 ])); | |
982 }); | |
983 }, passing: ['test 2']); | |
984 | |
985 expectTestsPass("an out-of-band error that's signaled after a timeout but " | |
986 "before the test completes plays nicely with other out-of-band callbacks", | |
987 () { | |
988 mock_clock.mock().run(); | |
989 var errors; | |
990 var onExceptionCallbackRun = false; | |
991 var onCompleteRunAfterOnExceptionCallback = false; | |
992 test('test 1', () { | |
993 currentSchedule.timeout = new Duration(milliseconds: 2); | |
994 | |
995 currentSchedule.onException.schedule(() { | |
996 sleep(1).then(wrapAsync((_) { | |
997 onExceptionCallbackRun = true; | |
998 })); | |
999 }); | |
1000 | |
1001 currentSchedule.onComplete.schedule(() { | |
1002 onCompleteRunAfterOnExceptionCallback = onExceptionCallbackRun; | |
1003 }); | |
1004 | |
1005 sleep(3).then(wrapAsync((_) { | |
1006 throw 'out-of-band'; | |
1007 })); | |
1008 }); | |
1009 | |
1010 test('test 2', () { | |
1011 expect(onCompleteRunAfterOnExceptionCallback, isTrue); | |
1012 }); | |
1013 }, passing: ['test 2']); | |
1014 | |
1015 expectTestsPass("a task that times out while waiting to handle an " | |
1016 "out-of-band error records both", () { | |
1017 mock_clock.mock().run(); | |
1018 var errors; | |
1019 test('test 1', () { | |
1020 currentSchedule.timeout = new Duration(milliseconds: 2); | |
1021 | |
1022 currentSchedule.onException.schedule(() { | |
1023 errors = currentSchedule.errors; | |
1024 }); | |
1025 | |
1026 schedule(() => sleep(4)); | |
1027 sleep(1).then((_) => currentSchedule.signalError('out-of-band')); | |
1028 }); | |
1029 | |
1030 test('test 2', () { | |
1031 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
1032 expect(errors.map((e) => e.error), equals([ | |
1033 "out-of-band", | |
1034 "The schedule timed out after 0:00:00.002000 of inactivity." | |
1035 ])); | |
1036 }); | |
1037 }, passing: ['test 2']); | |
1038 | |
1039 expectTestsPass("a task that has an error then times out waiting for an " | |
1040 "out-of-band callback records both", () { | |
1041 mock_clock.mock().run(); | |
1042 var errors; | |
1043 test('test 1', () { | |
1044 currentSchedule.timeout = new Duration(milliseconds: 2); | |
1045 | |
1046 currentSchedule.onException.schedule(() { | |
1047 errors = currentSchedule.errors; | |
1048 }); | |
1049 | |
1050 schedule(() { | |
1051 throw 'error'; | |
1052 }); | |
1053 wrapFuture(sleep(3)); | |
1054 }); | |
1055 | |
1056 test('test 2', () { | |
1057 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
1058 expect(errors.map((e) => e.error), equals([ | |
1059 "error", | |
1060 "The schedule timed out after 0:00:00.002000 of inactivity." | |
1061 ])); | |
1062 }); | |
1063 }, passing: ['test 2']); | |
1064 | |
1065 expectTestsPass("currentSchedule.heartbeat resets the timeout timer", () { | |
1066 mock_clock.mock().run(); | |
1067 test('test', () { | |
1068 currentSchedule.timeout = new Duration(milliseconds: 3); | |
1069 | |
1070 schedule(() { | |
1071 return sleep(2).then((_) { | |
1072 currentSchedule.heartbeat(); | |
1073 return sleep(2); | |
1074 }); | |
1075 }); | |
1076 }); | |
1077 }); | |
1078 | |
1079 // TODO(nweiz): test out-of-band post-timeout errors that are detected after | |
1080 // the test finishes once we can detect top-level errors (issue 8417). | |
1081 | |
1082 expectTestsPass("nested schedule() runs its function immediately (but " | |
1083 "asynchronously)", () { | |
1084 test('test', () { | |
1085 schedule(() { | |
1086 var nestedScheduleRun = false; | |
1087 schedule(() { | |
1088 nestedScheduleRun = true; | |
1089 }); | |
1090 | |
1091 expect(nestedScheduleRun, isFalse); | |
1092 expect(pumpEventQueue().then((_) => nestedScheduleRun), | |
1093 completion(isTrue)); | |
1094 }); | |
1095 }); | |
1096 }); | |
1097 | |
1098 expectTestsPass("out-of-band schedule() runs its function immediately (but " | |
1099 "asynchronously)", () { | |
1100 mock_clock.mock().run(); | |
1101 test('test', () { | |
1102 schedule(() { | |
1103 wrapFuture(sleep(1).then((_) { | |
1104 var nestedScheduleRun = false; | |
1105 schedule(() { | |
1106 nestedScheduleRun = true; | |
1107 }); | |
1108 | |
1109 expect(nestedScheduleRun, isFalse); | |
1110 expect(pumpEventQueue().then((_) => nestedScheduleRun), | |
1111 completion(isTrue)); | |
1112 })); | |
1113 }); | |
1114 }); | |
1115 }); | |
1116 | |
1117 expectTestsPass("nested schedule() calls don't wait for one another", () { | |
1118 mock_clock.mock().run(); | |
1119 test('test', () { | |
1120 var sleepFinished = false; | |
1121 schedule(() { | |
1122 schedule(() => sleep(1).then((_) { | |
1123 sleepFinished = true; | |
1124 })); | |
1125 schedule(() => expect(sleepFinished, isFalse)); | |
1126 }); | |
1127 }); | |
1128 }); | |
1129 | |
1130 expectTestsPass("nested schedule() calls block their parent task", () { | |
1131 mock_clock.mock().run(); | |
1132 test('test', () { | |
1133 var sleepFinished = false; | |
1134 schedule(() { | |
1135 schedule(() => sleep(1).then((_) { | |
1136 sleepFinished = true; | |
1137 })); | |
1138 }); | |
1139 | |
1140 schedule(() => expect(sleepFinished, isTrue)); | |
1141 }); | |
1142 }); | |
1143 | |
1144 expectTestsPass("out-of-band schedule() calls block their parent queue", () { | |
1145 mock_clock.mock().run(); | |
1146 test('test', () { | |
1147 var scheduleRun = false; | |
1148 wrapFuture(sleep(1).then((_) { | |
1149 schedule(() => sleep(1).then((_) { | |
1150 scheduleRun = true; | |
1151 })); | |
1152 })); | |
1153 | |
1154 currentSchedule.onComplete.schedule(() => expect(scheduleRun, isTrue)); | |
1155 }); | |
1156 }); | |
1157 | |
1158 expectTestsPass("nested schedule() calls forward their Future values", () { | |
1159 mock_clock.mock().run(); | |
1160 test('test', () { | |
1161 schedule(() { | |
1162 expect(schedule(() => 'foo'), completion(equals('foo'))); | |
1163 }); | |
1164 }); | |
1165 }); | |
1166 | |
1167 expectTestsPass("errors in nested schedule() calls are properly registered", | |
1168 () { | |
1169 var errors; | |
1170 test('test 1', () { | |
1171 currentSchedule.onException.schedule(() { | |
1172 errors = currentSchedule.errors; | |
1173 }); | |
1174 | |
1175 schedule(() { | |
1176 schedule(() { | |
1177 throw 'error'; | |
1178 }); | |
1179 }); | |
1180 }); | |
1181 | |
1182 test('test 2', () { | |
1183 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
1184 expect(errors.map((e) => e.error), equals(['error'])); | |
1185 }); | |
1186 }, passing: ['test 2']); | |
1187 | |
1188 expectTestsPass("nested scheduled blocks whose return values are passed to " | |
1189 "wrapFuture should report exceptions once", () { | |
1190 var errors; | |
1191 test('test 1', () { | |
1192 currentSchedule.onException.schedule(() { | |
1193 errors = currentSchedule.errors; | |
1194 }); | |
1195 | |
1196 schedule(() { | |
1197 wrapFuture(schedule(() { | |
1198 throw 'error'; | |
1199 })); | |
1200 | |
1201 return pumpEventQueue(); | |
1202 }); | |
1203 }); | |
1204 | |
1205 test('test 2', () { | |
1206 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
1207 expect(errors.map((e) => e.error), equals(['error'])); | |
1208 }); | |
1209 }, passing: ['test 2']); | |
1210 | |
1211 expectTestsPass("a nested task failing shouldn't short-circuit the parent " | |
1212 "task", () { | |
1213 var parentTaskFinishedBeforeOnComplete = false; | |
1214 test('test 1', () { | |
1215 var parentTaskFinished = false; | |
1216 currentSchedule.onComplete.schedule(() { | |
1217 parentTaskFinishedBeforeOnComplete = parentTaskFinished; | |
1218 }); | |
1219 | |
1220 schedule(() { | |
1221 schedule(() { | |
1222 throw 'error'; | |
1223 }); | |
1224 | |
1225 return sleep(1).then((_) { | |
1226 parentTaskFinished = true; | |
1227 }); | |
1228 }); | |
1229 }); | |
1230 | |
1231 test('test 2', () { | |
1232 expect(parentTaskFinishedBeforeOnComplete, isTrue); | |
1233 }); | |
1234 }, passing: ['test 2']); | |
1235 | |
1236 expectTestsPass("an error thrown in a scheduled task should be piped to that " | |
1237 "task's return value", () { | |
1238 var error; | |
1239 test('test 1', () { | |
1240 schedule(() { | |
1241 throw 'error'; | |
1242 }).catchError((e) { | |
1243 error = e; | |
1244 }); | |
1245 }); | |
1246 | |
1247 test('test 2', () { | |
1248 expect(error, new isInstanceOf<ScheduleError>()); | |
1249 expect(error.error, equals('error')); | |
1250 }); | |
1251 }, passing: ['test 2']); | |
1252 | |
1253 expectTestsPass("an error thrown in a scheduled task should be piped to " | |
1254 "future tasks' return values", () { | |
1255 var error; | |
1256 test('test 1', () { | |
1257 schedule(() { | |
1258 throw 'error'; | |
1259 }); | |
1260 | |
1261 schedule(() => null).catchError((e) { | |
1262 error = e; | |
1263 }); | |
1264 }); | |
1265 | |
1266 test('test 2', () { | |
1267 expect(error, new isInstanceOf<ScheduleError>()); | |
1268 expect(error.error, equals('error')); | |
1269 }); | |
1270 }, passing: ['test 2']); | |
1271 | |
1272 expectTestsPass("an out-of-band error should be piped to future tasks' " | |
1273 "return values, but not the current task's", () { | |
1274 mock_clock.mock().run(); | |
1275 var error; | |
1276 var firstTaskError = false; | |
1277 var secondTaskRun = false; | |
1278 test('test 1', () { | |
1279 schedule(() => sleep(2)).catchError((_) { | |
1280 firstTaskError = true; | |
1281 }); | |
1282 | |
1283 sleep(1).then(wrapAsync((_) { | |
1284 throw 'error'; | |
1285 })); | |
1286 | |
1287 schedule(() { | |
1288 secondTaskRun = true; | |
1289 }).catchError((e) { | |
1290 error = e; | |
1291 }); | |
1292 }); | |
1293 | |
1294 test('test 2', () { | |
1295 expect(firstTaskError, isFalse); | |
1296 expect(secondTaskRun, isFalse); | |
1297 expect(error, new isInstanceOf<ScheduleError>()); | |
1298 expect(error.error, equals('error')); | |
1299 }); | |
1300 }, passing: ['test 2']); | |
1301 | |
1302 expectTestsPass("expect(..., completes) with a completing future should pass", | |
1303 () { | |
1304 test('test', () { | |
1305 expect(pumpEventQueue(), completes); | |
1306 }); | |
1307 }); | |
1308 | |
1309 expectTestsPass("expect(..., completes) with a failing future should signal " | |
1310 "an out-of-band error", () { | |
1311 var errors; | |
1312 test('test 1', () { | |
1313 currentSchedule.onException.schedule(() { | |
1314 errors = currentSchedule.errors; | |
1315 }); | |
1316 | |
1317 expect(pumpEventQueue().then((_) { | |
1318 throw 'error'; | |
1319 }), completes); | |
1320 }); | |
1321 | |
1322 test('test 2', () { | |
1323 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
1324 expect(errors.map((e) => e.error), equals(['error'])); | |
1325 }); | |
1326 }, passing: ['test 2']); | |
1327 | |
1328 expectTestsPass("expect(..., completion(...)) with a matching future should " | |
1329 "pass", () { | |
1330 test('test', () { | |
1331 expect(pumpEventQueue().then((_) => 'foo'), completion(equals('foo'))); | |
1332 }); | |
1333 }); | |
1334 | |
1335 expectTestsPass("expect(..., completion(...)) with a non-matching future " | |
1336 "should signal an out-of-band error", () { | |
1337 var errors; | |
1338 test('test 1', () { | |
1339 currentSchedule.onException.schedule(() { | |
1340 errors = currentSchedule.errors; | |
1341 }); | |
1342 | |
1343 expect(pumpEventQueue().then((_) => 'foo'), completion(equals('bar'))); | |
1344 }); | |
1345 | |
1346 test('test 2', () { | |
1347 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
1348 expect(errors.length, equals(1)); | |
1349 expect(errors.first.error, new isInstanceOf<TestFailure>()); | |
1350 }); | |
1351 }, passing: ['test 2']); | |
1352 | |
1353 expectTestsPass("expect(..., completion(...)) with a failing future should " | |
1354 "signal an out-of-band error", () { | |
1355 var errors; | |
1356 test('test 1', () { | |
1357 currentSchedule.onException.schedule(() { | |
1358 errors = currentSchedule.errors; | |
1359 }); | |
1360 | |
1361 expect(pumpEventQueue().then((_) { | |
1362 throw 'error'; | |
1363 }), completion(equals('bar'))); | |
1364 }); | |
1365 | |
1366 test('test 2', () { | |
1367 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | |
1368 expect(errors.map((e) => e.error), equals(['error'])); | |
1369 }); | |
1370 }, passing: ['test 2']); | |
1371 | |
1372 expectTestsPass("aborting the schedule before it's started running should " | |
1373 "cause no tasks to be run", () { | |
1374 test('test', () { | |
1375 schedule(() { | |
1376 throw 'error'; | |
1377 }); | |
1378 | |
1379 currentSchedule.abort(); | |
1380 }); | |
1381 }); | |
1382 | |
1383 expectTestsPass("aborting the schedule while it's running should stop future " | |
1384 "tasks from running", () { | |
1385 test('test', () { | |
1386 schedule(currentSchedule.abort); | |
1387 | |
1388 schedule(() { | |
1389 throw 'error'; | |
1390 }); | |
1391 }); | |
1392 }); | |
1393 | |
1394 expectTestsPass("aborting the schedule while it's running shouldn't stop " | |
1395 "tasks in other queues from running", () { | |
1396 var onCompleteRun = false; | |
1397 test('test 1', () { | |
1398 schedule(currentSchedule.abort); | |
1399 | |
1400 currentSchedule.onComplete.schedule(() { | |
1401 onCompleteRun = true; | |
1402 }); | |
1403 }); | |
1404 | |
1405 test('test 2', () { | |
1406 expect(onCompleteRun, isTrue); | |
1407 }); | |
1408 }); | |
1409 | |
1410 expectTestsPass("aborting the schedule while it's running shouldn't stop " | |
1411 "out-of-band callbacks", () { | |
1412 test('test', () { | |
1413 var outOfBandFinished = false; | |
1414 schedule(() { | |
1415 wrapFuture(pumpEventQueue().then((_) { | |
1416 outOfBandFinished = true; | |
1417 })); | |
1418 | |
1419 currentSchedule.abort(); | |
1420 }); | |
1421 | |
1422 currentSchedule.onComplete.schedule(() { | |
1423 expect(outOfBandFinished, isTrue); | |
1424 }); | |
1425 }); | |
1426 }); | |
1427 | |
1428 expectTestsPass("aborting the schedule in a non-tasks queue should stop " | |
1429 "future tasks from running", () { | |
1430 test('test', () { | |
1431 currentSchedule.onComplete.schedule(() { | |
1432 currentSchedule.abort(); | |
1433 }); | |
1434 | |
1435 currentSchedule.onComplete.schedule(() { | |
1436 throw 'error'; | |
1437 }); | |
1438 }); | |
1439 }); | |
1440 | |
1441 expectTestsFail("aborting the schedule after an out-of-band error should " | |
1442 "still surface the error", () { | |
1443 test('test', () { | |
1444 schedule(() { | |
1445 currentSchedule.signalError('error'); | |
1446 currentSchedule.abort(); | |
1447 }); | |
1448 }); | |
1449 }); | |
1450 } | |
OLD | NEW |