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 test.backend.invoker; | 5 library test.backend.invoker; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:stack_trace/stack_trace.dart'; | 9 import 'package:stack_trace/stack_trace.dart'; |
10 | 10 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 /// | 61 /// |
62 /// This provides a view into the state of the test being executed. | 62 /// This provides a view into the state of the test being executed. |
63 LiveTest get liveTest => _controller.liveTest; | 63 LiveTest get liveTest => _controller.liveTest; |
64 LiveTestController _controller; | 64 LiveTestController _controller; |
65 | 65 |
66 /// Whether the test has been closed. | 66 /// Whether the test has been closed. |
67 /// | 67 /// |
68 /// Once the test is closed, [expect] and [expectAsync] will throw | 68 /// Once the test is closed, [expect] and [expectAsync] will throw |
69 /// [ClosedException]s whenever accessed to help the test stop executing as | 69 /// [ClosedException]s whenever accessed to help the test stop executing as |
70 /// soon as possible. | 70 /// soon as possible. |
71 bool get closed => _closed; | 71 bool get closed => _onCloseCompleter.isCompleted; |
72 bool _closed = false; | 72 |
| 73 /// A future that completes once the test has been closed. |
| 74 Future get onClose => _onCloseCompleter.future; |
| 75 final _onCloseCompleter = new Completer(); |
73 | 76 |
74 /// The test being run. | 77 /// The test being run. |
75 LocalTest get _test => liveTest.test as LocalTest; | 78 LocalTest get _test => liveTest.test as LocalTest; |
76 | 79 |
77 /// The test metadata merged with the suite metadata. | 80 /// The test metadata merged with the suite metadata. |
78 final Metadata metadata; | 81 final Metadata metadata; |
79 | 82 |
80 /// The outstanding callback counter for the current zone. | 83 /// The outstanding callback counter for the current zone. |
81 OutstandingCallbackCounter get _outstandingCallbacks { | 84 OutstandingCallbackCounter get _outstandingCallbacks { |
82 var counter = Zone.current[this]; | 85 var counter = Zone.current[this]; |
(...skipping 10 matching lines...) Expand all Loading... |
93 return Zone.current[#test.invoker]; | 96 return Zone.current[#test.invoker]; |
94 } | 97 } |
95 | 98 |
96 /// The timer for tracking timeouts. | 99 /// The timer for tracking timeouts. |
97 /// | 100 /// |
98 /// This will be `null` until the test starts running. | 101 /// This will be `null` until the test starts running. |
99 Timer _timeoutTimer; | 102 Timer _timeoutTimer; |
100 | 103 |
101 Invoker._(Suite suite, LocalTest test) | 104 Invoker._(Suite suite, LocalTest test) |
102 : metadata = suite.metadata.merge(test.metadata) { | 105 : metadata = suite.metadata.merge(test.metadata) { |
103 _controller = new LiveTestController(suite, test, _onRun, () { | 106 _controller = new LiveTestController( |
104 _closed = true; | 107 suite, test, _onRun, _onCloseCompleter.complete); |
105 }); | |
106 } | 108 } |
107 | 109 |
108 /// Tells the invoker that there's a callback running that it should wait for | 110 /// Tells the invoker that there's a callback running that it should wait for |
109 /// before considering the test successful. | 111 /// before considering the test successful. |
110 /// | 112 /// |
111 /// Each call to [addOutstandingCallback] should be followed by a call to | 113 /// Each call to [addOutstandingCallback] should be followed by a call to |
112 /// [removeOutstandingCallback] once the callbak is no longer running. Note | 114 /// [removeOutstandingCallback] once the callbak is no longer running. Note |
113 /// that only successful tests wait for outstanding callbacks; as soon as a | 115 /// that only successful tests wait for outstanding callbacks; as soon as a |
114 /// test experiences an error, any further calls to [addOutstandingCallback] | 116 /// test experiences an error, any further calls to [addOutstandingCallback] |
115 /// or [removeOutstandingCallback] will do nothing. | 117 /// or [removeOutstandingCallback] will do nothing. |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 // Use the invoker as a key so that multiple invokers can have different | 246 // Use the invoker as a key so that multiple invokers can have different |
245 // outstanding callback counters at once. | 247 // outstanding callback counters at once. |
246 this: outstandingCallbacksForBody | 248 this: outstandingCallbacksForBody |
247 }, | 249 }, |
248 zoneSpecification: new ZoneSpecification( | 250 zoneSpecification: new ZoneSpecification( |
249 print: (self, parent, zone, line) => _controller.print(line)), | 251 print: (self, parent, zone, line) => _controller.print(line)), |
250 onError: _handleError); | 252 onError: _handleError); |
251 }); | 253 }); |
252 } | 254 } |
253 } | 255 } |
OLD | NEW |