Skip to content

Commit 8f330c6

Browse files
authored
Merge pull request kubernetes#129420 from pohly/client-go-tools-cache-testhammercontroller-fix
client-go cache: fix TestHammerController
2 parents 7bfdda4 + 8e14035 commit 8f330c6

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

staging/src/k8s.io/client-go/tools/cache/controller_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,12 @@ func TestHammerController(t *testing.T) {
232232
// Run the controller and run it until we cancel.
233233
_, ctx := ktesting.NewTestContext(t)
234234
ctx, cancel := context.WithCancel(ctx)
235-
go controller.RunWithContext(ctx)
235+
var controllerWG sync.WaitGroup
236+
controllerWG.Add(1)
237+
go func() {
238+
defer controllerWG.Done()
239+
controller.RunWithContext(ctx)
240+
}()
236241

237242
// Let's wait for the controller to do its initial sync
238243
wait.Poll(100*time.Millisecond, wait.ForeverTestTimeout, func() (bool, error) {
@@ -293,8 +298,11 @@ func TestHammerController(t *testing.T) {
293298
time.Sleep(100 * time.Millisecond)
294299
cancel()
295300

296-
// TODO: Verify that no goroutines were leaked here and that everything shut
297-
// down cleanly.
301+
// Before we permanently lock this mutex, we have to be sure
302+
// that the controller has stopped running. At this point,
303+
// all goroutines should have stopped. Leak checking is
304+
// done by TestMain.
305+
controllerWG.Wait()
298306

299307
outputSetLock.Lock()
300308
t.Logf("got: %#v", outputSet)

0 commit comments

Comments
 (0)