fix goroutine that lives too long

Kubernetes-commit: 9a2e0fcb18bc9feb327122edc95a968a8d423af7
This commit is contained in:
Daniel Smith 2020-09-28 10:50:47 -07:00 committed by Kubernetes Publisher
parent 3f80aac972
commit 7e305c53b5
1 changed files with 6 additions and 1 deletions

View File

@ -22,6 +22,7 @@ import (
"reflect"
goruntime "runtime"
"strconv"
"sync"
"testing"
"time"
@ -941,8 +942,12 @@ func TestWatchBookmarksWithCorrectResourceVersion(t *testing.T) {
defer watcher.Stop()
done := make(chan struct{})
defer close(done)
var wg sync.WaitGroup
wg.Add(1)
defer wg.Wait() // We must wait for the waitgroup to exit before we terminate the cache or the server in prior defers
defer close(done) // call close first, so the goroutine knows to exit
go func() {
defer wg.Done()
for i := 0; i < 100; i++ {
select {
case <-done: