NetworkClock: add manually advanced clock for deterministic tests - #74
NetworkClock: add manually advanced clock for deterministic tests#74rpaulo wants to merge 1 commit into
Conversation
- Replace configurable-initial-value clock with a manual time backing store that tests can freeze and advance by hand - Route `now` and `nowAbsolute` through manual time when set, falling back to the system clock otherwise - Track continuous and absolute time separately, preserving nanosecond resolution beyond the system clock's microsecond truncation - Add tests covering freezing, advancing, and restoring the clock
tfpauly
left a comment
There was a problem hiding this comment.
Very cool! Mainly just questioning if we can use a better availability check.
| public struct Instant: InstantProtocol, CustomStringConvertible { | ||
| var time: NetworkDuration | ||
|
|
||
| #if !DisableDebugLogging |
There was a problem hiding this comment.
Seems a bit odd to tie this to debug logging — I assume this is just intended to compile stuff out on prod / release builds?
There was a problem hiding this comment.
Yeah pretty much to avoid the memory cost of adding a class. The CPU cost of the extra check in now() isn't that bad.
There was a problem hiding this comment.
Can we tie it being a debug build or some other trait? I don't think it necessarily makes sense to have this be the logging trait.
There was a problem hiding this comment.
We can't tie it to a debug build because we run tests in release mode AFAIK.
I didn't want a trait just for this, that's why I used the debug logging trait which is always enabled during the tests
store that tests can freeze and advance by hand
nowandnowAbsolutethrough manual time when set, fallingback to the system clock otherwise
resolution beyond the system clock's microsecond truncation