2cef9e2c7b
scheduled_test now uses stack chains for all of its error reporting. This also adds a number of [Chain.track] calls to work around issue 15105. R=rnystrom@google.com Review URL: https://codereview.chromium.org//93143002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@30836 260f80e4-7a28-3924-810f-c04153c831b5
61 lines
2.1 KiB
Dart
61 lines
2.1 KiB
Dart
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
library test_utils;
|
|
|
|
import 'dart:async';
|
|
|
|
import 'package:scheduled_test/scheduled_test.dart';
|
|
import 'package:scheduled_test/src/utils.dart';
|
|
import 'package:scheduled_test/src/mock_clock.dart' as mock_clock;
|
|
|
|
import 'metatest.dart';
|
|
|
|
export 'package:scheduled_test/src/utils.dart';
|
|
|
|
/// Wraps [input] to provide a timeout. If [input] completes before
|
|
/// [milliseconds] have passed, then the return value completes in the same way.
|
|
/// However, if [milliseconds] pass before [input] has completed, [onTimeout] is
|
|
/// run and its result is passed to [input] (with chaining, if it returns a
|
|
/// [Future]).
|
|
///
|
|
/// Note that timing out will not cancel the asynchronous operation behind
|
|
/// [input].
|
|
Future timeout(Future input, int milliseconds, onTimeout()) {
|
|
var completer = new Completer();
|
|
var timer = new Timer(new Duration(milliseconds: milliseconds), () {
|
|
chainToCompleter(syncFuture(onTimeout), completer);
|
|
});
|
|
input.then((value) {
|
|
if (completer.isCompleted) return;
|
|
timer.cancel();
|
|
completer.complete(value);
|
|
}).catchError((error, stackTrace) {
|
|
if (completer.isCompleted) return;
|
|
timer.cancel();
|
|
completer.completeError(error, stackTrace);
|
|
});
|
|
return completer.future;
|
|
}
|
|
|
|
/// Returns a [Future] that will complete in [milliseconds].
|
|
Future sleep(int milliseconds) {
|
|
var completer = new Completer();
|
|
mock_clock.newTimer(new Duration(milliseconds: milliseconds), () {
|
|
completer.complete();
|
|
});
|
|
return completer.future;
|
|
}
|
|
|
|
/// Sets up a timeout for every metatest in this file.
|
|
void setUpTimeout() {
|
|
metaSetUp(() {
|
|
// TODO(nweiz): We used to only increase the timeout to 10s for the Windows
|
|
// bots, but the Linux and Mac bots have started taking upwards of 5s when
|
|
// running pumpEventQueue, so we're increasing the timeout across the board
|
|
// (see issue 9248).
|
|
currentSchedule.timeout = new Duration(seconds: 10);
|
|
});
|
|
}
|