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

Side by Side Diff: lib/src/frontend/timeout.dart

Issue 1256833003: Add Timeout.none. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Fix invoker_test. Created 5 years, 4 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 unified diff | Download patch
« no previous file with comments | « lib/src/backend/metadata.dart ('k') | lib/src/runner/parse_metadata.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.frontend.timeout; 5 library test.frontend.timeout;
6 6
7 /// A class representing a modification to the default timeout for a test. 7 /// A class representing a modification to the default timeout for a test.
8 /// 8 ///
9 /// By default, a test will time out after 30 seconds. With [new Timeout], that 9 /// By default, a test will time out after 30 seconds. With [new Timeout], that
10 /// can be overridden entirely; with [new Timeout.factor], it can be scaled 10 /// can be overridden entirely; with [new Timeout.factor], it can be scaled
11 /// relative to the default. 11 /// relative to the default.
12 class Timeout { 12 class Timeout {
13 /// A constant indicating that a test should never time out.
14 static const none = const Timeout._none();
15
13 /// The timeout duration. 16 /// The timeout duration.
14 /// 17 ///
15 /// If set, this overrides the default duration entirely. It will be 18 /// If set, this overrides the default duration entirely. It's `null` for
16 /// non-`null` only when [scaleFactor] is `null`. 19 /// timeouts with a non-null [scaleFactor] and for [Timeout.none].
17 final Duration duration; 20 final Duration duration;
18 21
19 /// The timeout factor. 22 /// The timeout factor.
20 /// 23 ///
21 /// The default timeout will be multiplied by this to get the new timeout. 24 /// The default timeout will be multiplied by this to get the new timeout.
22 /// Thus a factor of 2 means that the test will take twice as long to time 25 /// Thus a factor of 2 means that the test will take twice as long to time
23 /// out, and a factor of 0.5 means that it will time out twice as quickly. 26 /// out, and a factor of 0.5 means that it will time out twice as quickly.
27 ///
28 /// This is `null` for timeouts with a non-null [duration] and for
29 /// [Timeout.none].
24 final num scaleFactor; 30 final num scaleFactor;
25 31
26 /// Declares an absolute timeout that overrides the default. 32 /// Declares an absolute timeout that overrides the default.
27 const Timeout(this.duration) 33 const Timeout(this.duration)
28 : scaleFactor = null; 34 : scaleFactor = null;
29 35
30 /// Declares a relative timeout that scales the default. 36 /// Declares a relative timeout that scales the default.
31 const Timeout.factor(this.scaleFactor) 37 const Timeout.factor(this.scaleFactor)
32 : duration = null; 38 : duration = null;
33 39
40 const Timeout._none()
41 : scaleFactor = null,
42 duration = null;
43
34 /// Returns a new [Timeout] that merges [this] with [other]. 44 /// Returns a new [Timeout] that merges [this] with [other].
35 /// 45 ///
36 /// If [other] declares a [duration], that takes precedence. Otherwise, this 46 /// If [other] declares a [duration], that takes precedence. Otherwise, this
37 /// timeout's [duration] or [factor] are multiplied by [other]'s [factor]. 47 /// timeout's [duration] or [factor] are multiplied by [other]'s [factor].
38 Timeout merge(Timeout other) { 48 Timeout merge(Timeout other) {
49 if (this == none || other == none) return none;
39 if (other.duration != null) return new Timeout(other.duration); 50 if (other.duration != null) return new Timeout(other.duration);
40 if (duration != null) return new Timeout(duration * other.scaleFactor); 51 if (duration != null) return new Timeout(duration * other.scaleFactor);
41 return new Timeout.factor(scaleFactor * other.scaleFactor); 52 return new Timeout.factor(scaleFactor * other.scaleFactor);
42 } 53 }
43 54
44 /// Returns a new [Duration] from applying [this] to [base]. 55 /// Returns a new [Duration] from applying [this] to [base].
45 Duration apply(Duration base) => 56 ///
46 duration == null ? base * scaleFactor : duration; 57 /// If this is [none], returns `null`.
58 Duration apply(Duration base) {
59 if (this == none) return null;
60 return duration == null ? base * scaleFactor : duration;
61 }
47 } 62 }
OLDNEW
« no previous file with comments | « lib/src/backend/metadata.dart ('k') | lib/src/runner/parse_metadata.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698