Skip to content

Commit

Permalink
feat: fix fanout test data race
Browse files Browse the repository at this point in the history
  • Loading branch information
georgehao committed Oct 22, 2022
1 parent d2b0e7c commit 1373cb0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/util/fanout/fanout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,27 @@ package fanout

import (
"context"
"sync"
"testing"
"time"
)

func TestFanout_Do(t *testing.T) {
ca := New("cache", WithWorker(1), WithBuffer(1024))
var run bool
var mtx sync.Mutex

ca.Do(context.Background(), func(c context.Context) {
mtx.Lock()
run = true
mtx.Unlock()
panic("error")
})

time.Sleep(time.Millisecond * 50)
t.Log("not panic")
mtx.Lock()
defer mtx.Unlock()
if !run {
t.Fatal("expect run be true")
}
Expand Down

0 comments on commit 1373cb0

Please sign in to comment.