OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library test.frontend.timeout; |
| 6 |
| 7 /// A class representing a modification to the default timeout for a test. |
| 8 /// |
| 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 |
| 11 /// relative to the default. |
| 12 class Timeout { |
| 13 /// The timeout duration. |
| 14 /// |
| 15 /// If set, this overrides the default duration entirely. It will be |
| 16 /// non-`null` only when [scaleFactor] is `null`. |
| 17 final Duration duration; |
| 18 |
| 19 /// The timeout factor. |
| 20 /// |
| 21 /// 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 |
| 23 /// out, and a factor of 0.5 means that it will time out twice as quickly. |
| 24 final num scaleFactor; |
| 25 |
| 26 /// Declares an absolute timeout that overrides the default. |
| 27 const Timeout(this.duration) |
| 28 : scaleFactor = null; |
| 29 |
| 30 /// Declares a relative timeout that scales the default. |
| 31 const Timeout.factor(this.scaleFactor) |
| 32 : duration = null; |
| 33 |
| 34 /// Returns a new [Timeout] that merges [this] with [other]. |
| 35 /// |
| 36 /// If [other] declares a [duration], that takes precedence. Otherwise, this |
| 37 /// timeout's [duration] or [factor] are multiplied by [other]'s [factor]. |
| 38 Timeout merge(Timeout other) { |
| 39 if (other.duration != null) return new Timeout(other.duration); |
| 40 if (duration != null) return new Timeout(duration * other.scaleFactor); |
| 41 return new Timeout.factor(scaleFactor * other.scaleFactor); |
| 42 } |
| 43 |
| 44 /// Returns a new [Duration] from applying [this] to [base]. |
| 45 Duration apply(Duration base) => |
| 46 duration == null ? base * scaleFactor : duration; |
| 47 } |
OLD | NEW |