UtilitiesTest JUnit can fail from time to time #1047
Labels
bug
Something isn't working
Developer Issue
An issue which affects PC2 Developers but doesn't directly affect users.
low priority
An issue that can be deferred
Describe the issue:
A git CI build failed on
UtilitiesTest.testgetDateTime()
.To Reproduce:
Extremely difficult to reproduce (see below).
Expected behavior:
The
UtilitiesTest.testgetDateTime()
should always succeed.Actual behavior:
The
UtilitiesTest.testgetDateTime()
can fail since the time can change between the initialUtilities.getDateTime()
and thenew Date()
on the next line inUtilitiesTest.java
. Basically, the test is obtaining a formatted time string (Utilities.DATE_TIME_FORMAT_STRING = "yyyyddMMhhmmss.SSS"
) from two different sources and comparing the non-millisecond part (first 15 characters), It is still possible (but extremely unlikely) that the first time string was obtained at, say,20251502141310.999
and the next one was at20251502141311.000
. Notice that the first 15 characters,20251502141310.
and20251502141311.
will compare differently causing the JUnit test to fail, and consequently, the CI Build process to fail.Environment:
All, but the Git CI in this case.
Log Info:
Screenshots:
Additional context:
Apparently the author thought about the fact that comparing the milliseconds could fail (a comment in the code:
// may not match actual milliseconds.
) However, no consideration was given to the fact that seconds may roll over as well (and consequently minutes, hours, etc.)I'm not exactly sure of the best way to fix this, other than just removing the test, or, perhaps if it fails, sleep 10ms and try again?
The text was updated successfully, but these errors were encountered: