Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fix fanout test data race #326

Merged
merged 1 commit into from
Oct 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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