| 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:stack_trace/stack_trace.dart'; | 7 import 'package:stack_trace/stack_trace.dart'; |
| 8 | 8 |
| 9 import '../backend/group.dart'; | 9 import '../backend/group.dart'; |
| 10 import '../frontend/expect.dart'; | 10 import '../frontend/expect.dart'; |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 runZonedWithValues(() async { | 272 runZonedWithValues(() async { |
| 273 _invokerZone = Zone.current; | 273 _invokerZone = Zone.current; |
| 274 _outstandingCallbackZones.add(Zone.current); | 274 _outstandingCallbackZones.add(Zone.current); |
| 275 | 275 |
| 276 // Run the test asynchronously so that the "running" state change has | 276 // Run the test asynchronously so that the "running" state change has |
| 277 // a chance to hit its event handler(s) before the test produces an | 277 // a chance to hit its event handler(s) before the test produces an |
| 278 // error. If an error is emitted before the first state change is | 278 // error. If an error is emitted before the first state change is |
| 279 // handled, we can end up with [onError] callbacks firing before the | 279 // handled, we can end up with [onError] callbacks firing before the |
| 280 // corresponding [onStateChange], which violates the timing | 280 // corresponding [onStateChange], which violates the timing |
| 281 // guarantees. | 281 // guarantees. |
| 282 // |
| 283 // Using [new Future] also avoids starving the DOM or other |
| 284 // microtask-level events. |
| 282 new Future(_test._body) | 285 new Future(_test._body) |
| 283 .then((_) => removeOutstandingCallback()); | 286 .then((_) => removeOutstandingCallback()); |
| 284 | 287 |
| 285 await _outstandingCallbacks.noOutstandingCallbacks; | 288 await _outstandingCallbacks.noOutstandingCallbacks; |
| 286 if (_timeoutTimer != null) _timeoutTimer.cancel(); | 289 if (_timeoutTimer != null) _timeoutTimer.cancel(); |
| 287 | 290 |
| 288 _controller.setState( | 291 _controller.setState( |
| 289 new State(Status.complete, liveTest.state.result)); | 292 new State(Status.complete, liveTest.state.result)); |
| 290 | 293 |
| 291 // Use [Timer.run] here to avoid starving the DOM or other | 294 _controller.completer.complete(); |
| 292 // non-microtask events. | |
| 293 Timer.run(_controller.completer.complete); | |
| 294 }, zoneValues: { | 295 }, zoneValues: { |
| 295 #test.invoker: this, | 296 #test.invoker: this, |
| 296 // Use the invoker as a key so that multiple invokers can have different | 297 // Use the invoker as a key so that multiple invokers can have different |
| 297 // outstanding callback counters at once. | 298 // outstanding callback counters at once. |
| 298 _counterKey: outstandingCallbacksForBody, | 299 _counterKey: outstandingCallbacksForBody, |
| 299 _closableKey: true | 300 _closableKey: true |
| 300 }, | 301 }, |
| 301 zoneSpecification: new ZoneSpecification( | 302 zoneSpecification: new ZoneSpecification( |
| 302 print: (self, parent, zone, line) => _controller.print(line)), | 303 print: (self, parent, zone, line) => _controller.print(line)), |
| 303 onError: _handleError); | 304 onError: _handleError); |
| 304 }); | 305 }); |
| 305 } | 306 } |
| 306 } | 307 } |
| OLD | NEW |