Skip to content

Commit

Permalink
CI: fix flaky test TestSingleFlight (#4469)
Browse files Browse the repository at this point in the history
  • Loading branch information
davies authored Mar 9, 2024
1 parent 64e7355 commit eb22e54
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/chunk/singleflight_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ func TestSingleFlight(t *testing.T) {
for i := 0; i < iters; i++ {
gp.Add(1)
go func(k int) {
p, _ := g.Execute(strconv.Itoa(k/1000), func() (*Page, error) {
time.Sleep(time.Microsecond * 50000) // In most cases 50ms is enough to run 1000 goroutines
p, _ := g.Execute(strconv.Itoa(k/100), func() (*Page, error) {
time.Sleep(time.Microsecond * 500000) // In most cases 500ms is enough to run 100 goroutines
atomic.AddInt32(&n, 1)
return NewOffPage(100), nil
})
p.Release()
cache.LoadOrStore(strconv.Itoa(k/1000), p)
cache.LoadOrStore(strconv.Itoa(k/100), p)
gp.Done()
}(i)
}
gp.Wait()

nv := int(atomic.LoadInt32(&n))
if nv != iters/1000 {
if nv != iters/100 {
t.Fatalf("singleflight doesn't take effect: %v", nv)
}

Expand Down

0 comments on commit eb22e54

Please sign in to comment.