File tree 2 files changed +19
-0
lines changed
2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -49,4 +49,10 @@ class BackoffMachine {
49
49
50
50
_waitsCompleted++ ;
51
51
}
52
+
53
+ /// Reset the machine to its initial state with minimal wait.
54
+ void reset () {
55
+ _startTime = null ;
56
+ _waitsCompleted = 0 ;
57
+ }
52
58
}
Original file line number Diff line number Diff line change @@ -51,4 +51,17 @@ void main() {
51
51
check (maxFromAllTrials).isGreaterThan (expectedMax * 0.75 );
52
52
}
53
53
});
54
+
55
+ test ('BackoffMachine resets duration' , () async {
56
+ final backoffMachine = BackoffMachine ();
57
+ await measureWait (backoffMachine.wait ());
58
+ final duration2 = await measureWait (backoffMachine.wait ());
59
+ check (backoffMachine.waitsCompleted).equals (2 );
60
+
61
+ backoffMachine.reset ();
62
+ check (backoffMachine.waitsCompleted).equals (0 );
63
+ final durationReset1 = await measureWait (backoffMachine.wait ());
64
+ check (durationReset1).isLessThan (duration2);
65
+ check (backoffMachine.waitsCompleted).equals (1 );
66
+ });
54
67
}
You can’t perform that action at this time.
0 commit comments