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 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 import 'package:fake_async/fake_async.dart'; | 7 import 'package:fake_async/fake_async.dart'; |
8 import 'package:test/src/backend/invoker.dart'; | 8 import 'package:test/src/backend/invoker.dart'; |
9 import 'package:test/src/backend/metadata.dart'; | 9 import 'package:test/src/backend/metadata.dart'; |
10 import 'package:test/src/backend/state.dart'; | 10 import 'package:test/src/backend/state.dart'; |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 expectErrors(liveTest, [(error) { | 635 expectErrors(liveTest, [(error) { |
636 expect(lastState.status, equals(Status.complete)); | 636 expect(lastState.status, equals(Status.complete)); |
637 expect(error, new isInstanceOf<TimeoutException>()); | 637 expect(error, new isInstanceOf<TimeoutException>()); |
638 }]); | 638 }]); |
639 | 639 |
640 liveTest.run(); | 640 liveTest.run(); |
641 async.elapse(new Duration(seconds: 15)); | 641 async.elapse(new Duration(seconds: 15)); |
642 }); | 642 }); |
643 }); | 643 }); |
644 }); | 644 }); |
| 645 |
| 646 group("waitForOutstandingCallbacks:", () { |
| 647 test("waits for the wrapped function to complete", () async { |
| 648 var functionCompleted = false; |
| 649 await Invoker.current.waitForOutstandingCallbacks(() async { |
| 650 await pumpEventQueue(); |
| 651 functionCompleted = true; |
| 652 }); |
| 653 |
| 654 expect(functionCompleted, isTrue); |
| 655 }); |
| 656 |
| 657 test("waits for registered callbacks in the wrapped function to run", |
| 658 () async { |
| 659 var callbackRun = false; |
| 660 await Invoker.current.waitForOutstandingCallbacks(() { |
| 661 pumpEventQueue().then(expectAsync((_) { |
| 662 callbackRun = true; |
| 663 })); |
| 664 }); |
| 665 |
| 666 expect(callbackRun, isTrue); |
| 667 }); |
| 668 |
| 669 test("doesn't automatically block the enclosing context", () async { |
| 670 var innerFunctionCompleted = false; |
| 671 await Invoker.current.waitForOutstandingCallbacks(() { |
| 672 Invoker.current.waitForOutstandingCallbacks(() async { |
| 673 await pumpEventQueue(); |
| 674 innerFunctionCompleted = true; |
| 675 }); |
| 676 }); |
| 677 |
| 678 expect(innerFunctionCompleted, isFalse); |
| 679 }); |
| 680 }); |
645 } | 681 } |
646 | 682 |
647 LocalTest _localTest(body(), {tearDown(), Metadata metadata}) { | 683 LocalTest _localTest(body(), {tearDown(), Metadata metadata}) { |
648 if (metadata == null) metadata = new Metadata(); | 684 if (metadata == null) metadata = new Metadata(); |
649 return new LocalTest("test", metadata, body, tearDown: tearDown); | 685 return new LocalTest("test", metadata, body, tearDown: tearDown); |
650 } | 686 } |
OLD | NEW |