mirror of
https://github.com/jimeh/rands.git
synced 2026-02-19 03:16:39 +00:00
test(uuid): fix flakiness on slower machines
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user