From bd5e1ea1c0e474772fbca602426977f1fb05960a Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Wed, 8 Jun 2016 13:18:56 -0700 Subject: [PATCH] e2e: fix race in ranging test tables Fix https://github.com/coreos/etcd/issues/5598. race conditions were detected in iterating the test table because the go func closure doesn't receive the 'puts' index in the argument. This can cause the test to run wrong put operations. --- e2e/ctl_v3_watch_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/e2e/ctl_v3_watch_test.go b/e2e/ctl_v3_watch_test.go index 6b7326d92..10a8bae56 100644 --- a/e2e/ctl_v3_watch_test.go +++ b/e2e/ctl_v3_watch_test.go @@ -68,13 +68,13 @@ func watchTest(cx ctlCtx) { } for i, tt := range tests { - go func() { - for j := range tt.puts { - if err := ctlV3Put(cx, tt.puts[j].key, tt.puts[j].val, ""); err != nil { + go func(i int, puts []kv) { + for j := range puts { + if err := ctlV3Put(cx, puts[j].key, puts[j].val, ""); err != nil { cx.t.Fatalf("watchTest #%d-%d: ctlV3Put error (%v)", i, j, err) } } - }() + }(i, tt.puts) if err := ctlV3Watch(cx, tt.args, tt.wkv...); err != nil { if cx.dialTimeout > 0 && !isGRPCTimedout(err) { cx.t.Errorf("watchTest #%d: ctlV3Watch error (%v)", i, err)