clock
clock copied to clipboard
Clock is a small library for mocking time in Go.
Original AfterFunc executes function in its own goroutine Mock should do it in the same way, otherwise tests doesn't cover races with this kind of timer
I believe the following demonstrates the issue: ``` c := clock.NewMock() go c.Ticker(time.Second).Stop() c.Add(time.Second) ``` Unfortunately, it's hard to get Go's race detector to catch this (I only ran it...
There's a data race if we call Mock.AfterFunc and Mock.Add concurrently. The included test demonstrates this with `go test -race`. ``` $ go test -race ================== WARNING: DATA RACE Read...
Add a minimal GitHub Workflow configuration for CI on the project. This will test against both currently supported versions of Go per the [Go Compatibility Guarantee](https://golang.org/doc/go1compat).
Because it often makes sense to override it with some app-specific implementation which waits for certain events instead of just sleeping 1 ms
Allow calling `Timer.Reset` from within the `AfterFunc` callback. This is a more far-reaching request than https://github.com/benbjohnson/clock/pull/27 because it not only requires the mutex to be unlocked, but also the stop...
Normal `time.Ticker`s support being `Stop()`ed, then later restarted by calling `Reset()`. However, mocked `clock.Ticker`s do not; once they are stopped they can never be restarted. This PR fixes that behavior,...
Hello, When running tests in my application with `-race`, they fail due to a race accessing `m.now` outside of a lock. To my knowledge there are two reads (`runNextTimer(...)` and...
Follow up to #49 Just like creating a new timer, a timer Reset should also fire the timer immediately.
The standard library versions of these behave monotonic, meaning that if I change the system clock while the program is running `time.After` and `time.Timer` still fire after the time I...