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
The TestCountdownShouldBeAbleToStop test was failing intermittently due to
a race condition in the StopTimer() implementation. Previously, the goroutine
used defer to set initilised=false, which executed after close(q) signaled
completion to StopTimer(). This allowed StopTimer() to return before the
state was properly cleaned up, causing isInitilised() checks to occasionally
see stale true values.
Fixed by explicitly calling setInitilised(false) before close(q), ensuring
the state is updated atomically before StopTimer() returns. This eliminates
the race condition and makes the test pass consistently.
Verified by running the test 30 times consecutively with no failures.
* feat: write duration calculation in countdown as
interface. add more inputs as function argument
* feat: ExpTimeoutDuration
* fix: three dots usage
* feat: refine exp duration
* feat: add exp timeout config and use it in countdown
* feat: remove const countdown
* feat: remove use of interface in countdown, use error
* fix: countdown reset timer problem
* fix: add default ExpTimeoutConfig for config