Skip to content

Commit 3892f66

Browse files
committed
fix data race in unittest
1 parent a1588cf commit 3892f66

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher_whitebox_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"testing"
2626
"time"
2727

28-
"k8s.io/api/core/v1"
28+
v1 "k8s.io/api/core/v1"
2929
"k8s.io/apimachinery/pkg/api/meta"
3030
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3131
"k8s.io/apimachinery/pkg/fields"
@@ -678,12 +678,16 @@ func TestDispatchingBookmarkEventsWithConcurrentStop(t *testing.T) {
678678
t.Fatalf("failure to update version of object (%d) %#v", bookmark.ResourceVersion, bookmark.Object)
679679
}
680680

681+
wg := sync.WaitGroup{}
682+
wg.Add(2)
681683
go func() {
682684
cacher.dispatchEvent(bookmark)
685+
wg.Done()
683686
}()
684687

685688
go func() {
686689
w.Stop()
690+
wg.Done()
687691
}()
688692

689693
done := make(chan struct{})
@@ -700,5 +704,6 @@ func TestDispatchingBookmarkEventsWithConcurrentStop(t *testing.T) {
700704
t.Fatal("receive result timeout")
701705
}
702706
w.Stop()
707+
wg.Wait()
703708
}
704709
}

0 commit comments

Comments
 (0)