Skip to content

Commit

Permalink
The Staleness tests can't be parallel, because they use the global `N…
Browse files Browse the repository at this point in the history
…owFunc`
  • Loading branch information
RichieSams committed Feb 22, 2024
1 parent 4b0be90 commit 4917d1f
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions internal/exp/metrics/staleness/staleness_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
)

func TestStaleness(t *testing.T) {
t.Parallel()

max := 1 * time.Second
stalenessMap := NewStaleness[int](
max,
Expand Down Expand Up @@ -46,20 +44,20 @@ func TestStaleness(t *testing.T) {
valueD := 0

// Add the values to the map
nowFunc = func() time.Time { return timeA }
NowFunc = func() time.Time { return timeA }
stalenessMap.Store(idA, valueA)
nowFunc = func() time.Time { return timeB }
NowFunc = func() time.Time { return timeB }
stalenessMap.Store(idB, valueB)
nowFunc = func() time.Time { return timeC }
NowFunc = func() time.Time { return timeC }
stalenessMap.Store(idC, valueC)
nowFunc = func() time.Time { return timeD }
NowFunc = func() time.Time { return timeD }
stalenessMap.Store(idD, valueD)

// Set the time to 2.5s and run expire
// This should remove B, but the others should remain
// (now == 2.5s, B == 1s, max == 1s)
// now > B + max
nowFunc = func() time.Time { return initialTime.Add(2500 * time.Millisecond) }
NowFunc = func() time.Time { return initialTime.Add(2500 * time.Millisecond) }
stalenessMap.ExpireOldEntries()
validateStalenessMapEntries(t,
map[identity.Stream]int{
Expand All @@ -74,7 +72,7 @@ func TestStaleness(t *testing.T) {
// This should remove A and C, but D should remain
// (now == 2.5s, A == 2s, C == 3s, max == 1s)
// now > A + max AND now > C + max
nowFunc = func() time.Time { return initialTime.Add(4500 * time.Millisecond) }
NowFunc = func() time.Time { return initialTime.Add(4500 * time.Millisecond) }
stalenessMap.ExpireOldEntries()
validateStalenessMapEntries(t,
map[identity.Stream]int{
Expand Down

0 comments on commit 4917d1f

Please sign in to comment.