mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 13:21:37 +00:00
fix(common/countdown): stabilize reset timing assertions (#2120)
Fix flaky countdown reset tests by performing an explicit second Reset before validating the second timeout window, and using a boundary-safe time check.
Observed failure:
--- FAIL: TestCountdownShouldReset (14.00s)
countdown_test.go:53: Correctly reset the countdown once
countdown_test.go:72: Countdown did not reset correctly second time
This commit is contained in:
parent
8331c1431f
commit
0581dec6b7
1 changed files with 8 additions and 4 deletions
|
|
@ -60,13 +60,15 @@ firstReset:
|
|||
}
|
||||
}
|
||||
|
||||
// Now the countdown is paused after calling the callback function, let's reset it again
|
||||
// The countdown keeps running after calling the callback; it is still initialised.
|
||||
// Reset it again to verify that an explicit Reset extends the timeout by a full interval.
|
||||
assert.True(t, countdown.isInitilised())
|
||||
countdown.Reset(fakeI, 0, 0)
|
||||
expectedTimeAfterReset := time.Now().Add(5000 * time.Millisecond)
|
||||
<-called
|
||||
// Always initilised
|
||||
assert.True(t, countdown.isInitilised())
|
||||
if time.Now().After(expectedTimeAfterReset) {
|
||||
if !time.Now().Before(expectedTimeAfterReset) {
|
||||
t.Log("Correctly reset the countdown second time")
|
||||
} else {
|
||||
t.Fatalf("Countdown did not reset correctly second time")
|
||||
|
|
@ -109,13 +111,15 @@ firstReset:
|
|||
}
|
||||
}
|
||||
|
||||
// Now the countdown is paused after calling the callback function, let's reset it again
|
||||
// The countdown continues running (auto-resets) after calling the callback
|
||||
// function; reset it again to verify it can still be reset after an error
|
||||
assert.True(t, countdown.isInitilised())
|
||||
countdown.Reset(fakeI, 0, 0)
|
||||
expectedTimeAfterReset := time.Now().Add(5000 * time.Millisecond)
|
||||
<-called
|
||||
// Always initilised
|
||||
assert.True(t, countdown.isInitilised())
|
||||
if time.Now().After(expectedTimeAfterReset) {
|
||||
if !time.Now().Before(expectedTimeAfterReset) {
|
||||
t.Log("Correctly reset the countdown second time")
|
||||
} else {
|
||||
t.Fatalf("Countdown did not reset correctly second time")
|
||||
|
|
|
|||
Loading…
Reference in a new issue