fix data race in testWatchOverlapContextCancel #14003

This commit is contained in:
eval-exec 2022-05-01 20:53:02 +08:00
parent 00d6d40aea
commit 755e2e7755

View File

@ -1072,6 +1072,8 @@ func testWatchOverlapContextCancel(t *testing.T, f func(*integration2.Cluster))
t.Fatal(err)
}
ch := make(chan struct{}, n)
tCtx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()
for i := 0; i < n; i++ {
go func() {
defer func() { ch <- struct{}{} }()
@ -1079,6 +1081,12 @@ func testWatchOverlapContextCancel(t *testing.T, f func(*integration2.Cluster))
ctx, cancel := context.WithCancel(ctxs[idx])
ctxc[idx] <- struct{}{}
wch := cli.Watch(ctx, "abc", clientv3.WithRev(1))
select {
case <-tCtx.Done():
cancel()
return
default:
}
f(clus)
select {
case _, ok := <-wch: