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

@@ -547,10 +547,13 @@ func TestUUIDv7(t *testing.T) {
timestampBytes := int64(b[0])<<40 | int64(b[1])<<32 | int64(b[2])<<24 | timestampBytes := int64(b[0])<<40 | int64(b[1])<<32 | int64(b[2])<<24 |
int64(b[3])<<16 | int64(b[4])<<8 | int64(b[5]) int64(b[3])<<16 | int64(b[4])<<8 | int64(b[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) tsTime := time.UnixMilli(timestampBytes)
require.WithinDuration(t, time.Now(), tsTime, 100*time.Millisecond, require.WithinDuration(t, time.Now(), tsTime, 10*time.Second,
"timestamp is not within 100 milliseconds of current time") "timestamp is not within 10 seconds of current time",
)
// After the first UUID, verify that UUIDs are monotonically increasing // After the first UUID, verify that UUIDs are monotonically increasing
if i > 0 && timestampBytes < lastTimestampBytes { if i > 0 && timestampBytes < lastTimestampBytes {

View File

@@ -680,10 +680,12 @@ func TestUUIDv7(t *testing.T) {
timestampBytes := int64(b[0])<<40 | int64(b[1])<<32 | timestampBytes := int64(b[0])<<40 | int64(b[1])<<32 |
int64(b[2])<<24 | int64(b[3])<<16 | int64(b[4])<<8 | int64(b[5]) int64(b[2])<<24 | int64(b[3])<<16 | int64(b[4])<<8 | int64(b[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) tsTime := time.UnixMilli(timestampBytes)
require.WithinDuration(t, time.Now(), tsTime, 100*time.Millisecond, require.WithinDuration(t, time.Now(), tsTime, 10*time.Second,
"timestamp is not within 100 milliseconds of current time", "timestamp is not within 10 seconds of current time",
) )
// After the first UUID, verify that UUIDs are monotonically increasing // After the first UUID, verify that UUIDs are monotonically increasing

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[2])<<24 | int64(got[3])<<16 | int64(got[4])<<8 |
int64(got[5]) 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) tsTime := time.UnixMilli(timestampBytes)
require.WithinDuration(t, time.Now(), tsTime, 100*time.Millisecond, require.WithinDuration(t, time.Now(), tsTime, 10*time.Second,
"timestamp is not within 100 milliseconds of current time") "timestamp is not within 10 seconds of current time",
)
// After the first UUID, verify that UUIDs are monotonically increasing // After the first UUID, verify that UUIDs are monotonically increasing
if i > 0 && timestampBytes < lastTimestampBytes { if i > 0 && timestampBytes < lastTimestampBytes {