From 755e2e775557a221e764f84dfcbf009a33b6f307 Mon Sep 17 00:00:00 2001 From: eval-exec Date: Sun, 1 May 2022 20:53:02 +0800 Subject: [PATCH] fix data race in testWatchOverlapContextCancel #14003 --- tests/integration/clientv3/watch_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/integration/clientv3/watch_test.go b/tests/integration/clientv3/watch_test.go index d52cb8a7c..a1f1dc287 100644 --- a/tests/integration/clientv3/watch_test.go +++ b/tests/integration/clientv3/watch_test.go @@ -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: