test(uuid): fix flakiness on slower machines

This commit is contained in:
2025-03-07 01:16:39 +00:00
parent ec94efe49e
commit f4dccc6e46
3 changed files with 17 additions and 9 deletions

View File

@@ -43,10 +43,13 @@ func TestUUIDv7(t *testing.T) {
int64(got[2])<<24 | int64(got[3])<<16 | int64(got[4])<<8 |
int64(got[5])
// Verify timestamp is within 100 milliseconds of current time.
// Verify timestamp is within 10 seconds of current time. This is a
// sanity check to ensure the UUID is not too far off from the current
// time, while allowing tests to pass on super slow machines.
tsTime := time.UnixMilli(timestampBytes)
require.WithinDuration(t, time.Now(), tsTime, 100*time.Millisecond,
"timestamp is not within 100 milliseconds of current time")
require.WithinDuration(t, time.Now(), tsTime, 10*time.Second,
"timestamp is not within 10 seconds of current time",
)
// After the first UUID, verify that UUIDs are monotonically increasing
if i > 0 && timestampBytes < lastTimestampBytes {