@@ -36,6 +36,25 @@ class BackoffMachine {
36
36
/// not the (random) previous wait duration itself.
37
37
static const double base = 2 ;
38
38
39
+ /// In debug mode, overrides the duration of the backoff wait.
40
+ ///
41
+ /// Outside of debug mode, this is always `null` and the setter has no effect.
42
+ static Duration ? get debugDuration {
43
+ Duration ? result;
44
+ assert (() {
45
+ result = _debugDuration;
46
+ return true ;
47
+ }());
48
+ return result;
49
+ }
50
+ static Duration ? _debugDuration;
51
+ static set debugDuration (Duration ? newValue) {
52
+ assert (() {
53
+ _debugDuration = newValue;
54
+ return true ;
55
+ }());
56
+ }
57
+
39
58
/// A future that resolves after an appropriate backoff time,
40
59
/// with jitter applied to capped exponential growth.
41
60
///
@@ -66,8 +85,8 @@ class BackoffMachine {
66
85
Future <void > wait () async {
67
86
final bound = _minDuration (maxBound,
68
87
firstBound * pow (base , _waitsCompleted));
69
- final duration = _maxDuration (const Duration (microseconds: 1 ),
70
- bound * Random ().nextDouble ());
88
+ final duration = debugDuration ?? _maxDuration (const Duration (microseconds: 1 ),
89
+ bound * Random ().nextDouble ());
71
90
await Future <void >.delayed (duration);
72
91
_waitsCompleted++ ;
73
92
}
0 commit comments