jonboulle / clockwork

a fake clock for golang
Apache License 2.0
625 stars 57 forks source link

NewFakeClock returns a deterministic time #57

Closed DPJacques closed 1 year ago

DPJacques commented 1 year ago

I found a large number of authors are writing tests that depend on the deterministic time returned by NewFakeClock. I found this out the hard way when I upgraded us to https://github.com/jonboulle/clockwork/pull/52, which changed this default.

I believe using a deterministic time when none is specified is an anti-pattern. If a test requires a deterministic time, authors should use NewFackClockAt to make the timestamp requirement explicit. This is similar to how Go's map iterating order is non-deterministic.

I made https://github.com/jonboulle/clockwork/pull/55 as a suggestion, which uses a random time from the year 1970 (excluding the Unix epoch time), but I am open to other thoughts/suggestions.

sagikazarmark commented 1 year ago

Fixed in #55