Skip to content

Commit f389ce7

Browse files
committed
Fix flaky TestRangeBig
Use a fixed base time instead of time.Now() in a loop. Adjacent iterations could receive the same timestamp due to clock granularity, causing non-unique values and off-by-one cardinality in range queries.
1 parent 8923a74 commit f389ce7

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

roaring64/bsi64_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,12 @@ func TestRangeBig(t *testing.T) {
165165

166166
bsi := NewDefaultBSI()
167167

168-
// Populate large timestamp values
168+
// Use a fixed base time so values are deterministic and strictly ordered.
169+
base := time.Date(3026, 1, 1, 0, 0, 0, 0, time.UTC)
169170
for i := 0; i <= 100; i++ {
170-
t := time.Now()
171-
newTime := t.AddDate(1000, 0, 0) // Add 1000 years
172-
secs := newTime.UnixMilli() / 1000
173-
nano := int32(newTime.Nanosecond())
171+
ts := base.Add(time.Duration(i) * time.Second)
172+
secs := ts.UnixMilli() / 1000
173+
nano := int32(ts.Nanosecond())
174174
bigTime := secondsAndNanosToBigInt(secs, nano)
175175
bsi.SetBigValue(uint64(i), bigTime)
176176
}

0 commit comments

Comments
 (0)