Skip to content

Commit

Permalink
fix(ci): fix the flaky Cache_Set test
Browse files Browse the repository at this point in the history
  • Loading branch information
maypok86 committed Sep 19, 2024
1 parent 542e8af commit 927442c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,19 @@ func TestCache_Set(t *testing.T) {
var mutex sync.Mutex
m := make(map[DeletionCause]int)
statsCounter := stats.NewCounter()
done := make(chan struct{})
count := 0
c, err := NewBuilder[int, int]().
MaximumSize(size).
WithTTL(time.Minute).
RecordStats(statsCounter).
OnDeletion(func(e DeletionEvent[int, int]) {
mutex.Lock()
count++
m[e.Cause]++
if count == size {
done <- struct{}{}
}
mutex.Unlock()
}).
Build()
Expand Down Expand Up @@ -342,6 +348,7 @@ func TestCache_Set(t *testing.T) {
t.Fatalf("cache hit ratio should be 1.0, but got %v", ratio)
}

<-done
mutex.Lock()
defer mutex.Unlock()
if len(m) != 1 || m[CauseReplacement] != size {
Expand Down

0 comments on commit 927442c

Please sign in to comment.