In our codebase someone has written a test where we have something like this:
void someTestFunc()
{
SomeObject obj = createObject(); // SomeObject contains an Instant from when it was updated (UpdatedTime)
Instant before = Instant.now();
updateObject(obj); // mutated the timestamp in SomeObject
Instant after = Instant.now();
assertTrue(before.isBefore(obj.UpdatedTime()));
assertTrue(after.isAfter(obj.UpdatedTime));
}
I'm compiling and running these tests on Windows 10, while they are doing it on Mac/Linux, and they seem to always get increasing timestamps when calling Instant.now(), while I sometimes seem to get the same timestamp in a row (i.e. 'UpdatedTime' and 'after' is equal, but before is earlier).
If I try running the tests using WSL2, they all pass nicely, but I am unable to draw a proper conclusion as there is necessarily some slow down when executing through WSL2.
The asserts can of course be rearranged to make the tests pass, but that's not the issue I'm curious about.
Is there a difference in the resolution/reliability of the time services on the platforms (is Windows more prone to give two sequential equal timestamps), or could it be as trivial as my computer is newer and faster?