mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
fix goroutine that lives too long
This commit is contained in:
parent
db9f1e91d9
commit
9a2e0fcb18
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user