From f4dccc6e46d59a450c37c406b00343e8ff221b65 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Fri, 7 Mar 2025 01:16:39 +0000 Subject: [PATCH] test(uuid): fix flakiness on slower machines --- randsmust/strings_test.go | 9 ++++++--- strings_test.go | 8 +++++--- uuid/version_7_test.go | 9 ++++++--- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/randsmust/strings_test.go b/randsmust/strings_test.go index 508bbaf..9a48281 100644 --- a/randsmust/strings_test.go +++ b/randsmust/strings_test.go @@ -547,10 +547,13 @@ func TestUUIDv7(t *testing.T) { timestampBytes := int64(b[0])<<40 | int64(b[1])<<32 | 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) - 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 { diff --git a/strings_test.go b/strings_test.go index d7eefe6..4d9b36b 100644 --- a/strings_test.go +++ b/strings_test.go @@ -680,10 +680,12 @@ func TestUUIDv7(t *testing.T) { timestampBytes := int64(b[0])<<40 | int64(b[1])<<32 | 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) - 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 diff --git a/uuid/version_7_test.go b/uuid/version_7_test.go index e0af351..a095f98 100644 --- a/uuid/version_7_test.go +++ b/uuid/version_7_test.go @@ -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 {