Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1390)

Unified Diff: mojo/public/dart/third_party/test/lib/src/frontend/timeout.dart

Issue 1346773002: Stop running pub get at gclient sync time and fix build bugs (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/dart/third_party/test/lib/src/frontend/timeout.dart
diff --git a/mojo/public/dart/third_party/test/lib/src/frontend/timeout.dart b/mojo/public/dart/third_party/test/lib/src/frontend/timeout.dart
new file mode 100644
index 0000000000000000000000000000000000000000..78fea385fe775b667fdd6fb1a3571c51fa5c76d4
--- /dev/null
+++ b/mojo/public/dart/third_party/test/lib/src/frontend/timeout.dart
@@ -0,0 +1,62 @@
+// Copyright (c) 2015, 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.frontend.timeout;
+
+/// A class representing a modification to the default timeout for a test.
+///
+/// By default, a test will time out after 30 seconds. With [new Timeout], that
+/// can be overridden entirely; with [new Timeout.factor], it can be scaled
+/// relative to the default.
+class Timeout {
+ /// A constant indicating that a test should never time out.
+ static const none = const Timeout._none();
+
+ /// The timeout duration.
+ ///
+ /// If set, this overrides the default duration entirely. It's `null` for
+ /// timeouts with a non-null [scaleFactor] and for [Timeout.none].
+ final Duration duration;
+
+ /// The timeout factor.
+ ///
+ /// The default timeout will be multiplied by this to get the new timeout.
+ /// Thus a factor of 2 means that the test will take twice as long to time
+ /// out, and a factor of 0.5 means that it will time out twice as quickly.
+ ///
+ /// This is `null` for timeouts with a non-null [duration] and for
+ /// [Timeout.none].
+ final num scaleFactor;
+
+ /// Declares an absolute timeout that overrides the default.
+ const Timeout(this.duration)
+ : scaleFactor = null;
+
+ /// Declares a relative timeout that scales the default.
+ const Timeout.factor(this.scaleFactor)
+ : duration = null;
+
+ const Timeout._none()
+ : scaleFactor = null,
+ duration = null;
+
+ /// Returns a new [Timeout] that merges [this] with [other].
+ ///
+ /// If [other] declares a [duration], that takes precedence. Otherwise, this
+ /// timeout's [duration] or [factor] are multiplied by [other]'s [factor].
+ Timeout merge(Timeout other) {
+ if (this == none || other == none) return none;
+ if (other.duration != null) return new Timeout(other.duration);
+ if (duration != null) return new Timeout(duration * other.scaleFactor);
+ return new Timeout.factor(scaleFactor * other.scaleFactor);
+ }
+
+ /// Returns a new [Duration] from applying [this] to [base].
+ ///
+ /// If this is [none], returns `null`.
+ Duration apply(Duration base) {
+ if (this == none) return null;
+ return duration == null ? base * scaleFactor : duration;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698