From 92d0f8e6cc3b3d40194759afa4c7f2880dd5ada4 Mon Sep 17 00:00:00 2001 From: Mengjiao Liu Date: Tue, 18 May 2021 18:00:03 +0800 Subject: [PATCH] Prevent data race condition in csi unit tests --- staging/src/k8s.io/client-go/testing/fake.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/staging/src/k8s.io/client-go/testing/fake.go b/staging/src/k8s.io/client-go/testing/fake.go index 8b9ee149c83..3ab9c1b075d 100644 --- a/staging/src/k8s.io/client-go/testing/fake.go +++ b/staging/src/k8s.io/client-go/testing/fake.go @@ -106,11 +106,15 @@ func (c *Fake) PrependReactor(verb, resource string, reaction ReactionFunc) { // AddWatchReactor appends a reactor to the end of the chain. func (c *Fake) AddWatchReactor(resource string, reaction WatchReactionFunc) { + c.Lock() + defer c.Unlock() c.WatchReactionChain = append(c.WatchReactionChain, &SimpleWatchReactor{resource, reaction}) } // PrependWatchReactor adds a reactor to the beginning of the chain. func (c *Fake) PrependWatchReactor(resource string, reaction WatchReactionFunc) { + c.Lock() + defer c.Unlock() c.WatchReactionChain = append([]WatchReactor{&SimpleWatchReactor{resource, reaction}}, c.WatchReactionChain...) }