mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 12:07:47 +00:00
client-go cache: fix TestHammerController
The test relied on a 100ms sleep to ensure that controller was done. If that race was lost, one goroutine was intentionally prevented from completing by locking a mutex permanently. A TODO was left about detecting that. Adding goroutine leak checking in https://github.com/kubernetes/kubernetes/pull/126387 revealed that this race indeed sometimes is lost because the goroutine leaked (https://github.com/kubernetes/kubernetes/issues/129400). Waiting for controller shutdown instead of relying on timing should fix this.
This commit is contained in:
parent
7bfdda4696
commit
8e1403563a
@ -232,7 +232,12 @@ func TestHammerController(t *testing.T) {
|
|||||||
// Run the controller and run it until we cancel.
|
// Run the controller and run it until we cancel.
|
||||||
_, ctx := ktesting.NewTestContext(t)
|
_, ctx := ktesting.NewTestContext(t)
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
go controller.RunWithContext(ctx)
|
var controllerWG sync.WaitGroup
|
||||||
|
controllerWG.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer controllerWG.Done()
|
||||||
|
controller.RunWithContext(ctx)
|
||||||
|
}()
|
||||||
|
|
||||||
// Let's wait for the controller to do its initial sync
|
// Let's wait for the controller to do its initial sync
|
||||||
wait.Poll(100*time.Millisecond, wait.ForeverTestTimeout, func() (bool, error) {
|
wait.Poll(100*time.Millisecond, wait.ForeverTestTimeout, func() (bool, error) {
|
||||||
@ -293,8 +298,11 @@ func TestHammerController(t *testing.T) {
|
|||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
cancel()
|
cancel()
|
||||||
|
|
||||||
// TODO: Verify that no goroutines were leaked here and that everything shut
|
// Before we permanently lock this mutex, we have to be sure
|
||||||
// down cleanly.
|
// that the controller has stopped running. At this point,
|
||||||
|
// all goroutines should have stopped. Leak checking is
|
||||||
|
// done by TestMain.
|
||||||
|
controllerWG.Wait()
|
||||||
|
|
||||||
outputSetLock.Lock()
|
outputSetLock.Lock()
|
||||||
t.Logf("got: %#v", outputSet)
|
t.Logf("got: %#v", outputSet)
|
||||||
|
Loading…
Reference in New Issue
Block a user