| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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_utils; | 5 library test_utils; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 | 9 |
| 10 import 'package:scheduled_test/scheduled_test.dart'; | 10 import 'package:scheduled_test/scheduled_test.dart'; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 /// [input]. | 25 /// [input]. |
| 26 Future timeout(Future input, int milliseconds, onTimeout()) { | 26 Future timeout(Future input, int milliseconds, onTimeout()) { |
| 27 var completer = new Completer(); | 27 var completer = new Completer(); |
| 28 var timer = new Timer(new Duration(milliseconds: milliseconds), () { | 28 var timer = new Timer(new Duration(milliseconds: milliseconds), () { |
| 29 chainToCompleter(new Future.of(onTimeout), completer); | 29 chainToCompleter(new Future.of(onTimeout), completer); |
| 30 }); | 30 }); |
| 31 input.then((value) { | 31 input.then((value) { |
| 32 if (completer.isCompleted) return; | 32 if (completer.isCompleted) return; |
| 33 timer.cancel(); | 33 timer.cancel(); |
| 34 completer.complete(value); | 34 completer.complete(value); |
| 35 }).catchError((e) { | 35 }).catchError((error) { |
| 36 if (completer.isCompleted) return; | 36 if (completer.isCompleted) return; |
| 37 timer.cancel(); | 37 timer.cancel(); |
| 38 completer.completeError(e.error, e.stackTrace); | 38 completer.completeError(error); |
| 39 }); | 39 }); |
| 40 return completer.future; | 40 return completer.future; |
| 41 } | 41 } |
| 42 | 42 |
| 43 /// Returns a [Future] that will complete in [milliseconds]. | 43 /// Returns a [Future] that will complete in [milliseconds]. |
| 44 Future sleep(int milliseconds) { | 44 Future sleep(int milliseconds) { |
| 45 var completer = new Completer(); | 45 var completer = new Completer(); |
| 46 mock_clock.newTimer(new Duration(milliseconds: milliseconds), () { | 46 mock_clock.newTimer(new Duration(milliseconds: milliseconds), () { |
| 47 completer.complete(); | 47 completer.complete(); |
| 48 }); | 48 }); |
| 49 return completer.future; | 49 return completer.future; |
| 50 } | 50 } |
| 51 | 51 |
| 52 /// Sets up a timeout for every metatest in this file. | 52 /// Sets up a timeout for every metatest in this file. |
| 53 void setUpTimeout() { | 53 void setUpTimeout() { |
| 54 metaSetUp(() { | 54 metaSetUp(() { |
| 55 // TODO(nweiz): We used to only increase the timeout to 10s for the Windows | 55 // TODO(nweiz): We used to only increase the timeout to 10s for the Windows |
| 56 // bots, but the Linux and Mac bots have started taking upwards of 5s when | 56 // bots, but the Linux and Mac bots have started taking upwards of 5s when |
| 57 // running pumpEventQueue, so we're increasing the timeout across the board | 57 // running pumpEventQueue, so we're increasing the timeout across the board |
| 58 // (see issue 9248). | 58 // (see issue 9248). |
| 59 currentSchedule.timeout = new Duration(seconds: 10); | 59 currentSchedule.timeout = new Duration(seconds: 10); |
| 60 }); | 60 }); |
| 61 } | 61 } |
| OLD | NEW |