From fef7ce9ff04a551eff9b58bfedc4a48ec91bc3d6 Mon Sep 17 00:00:00 2001 From: Gaurav Singh Date: Sat, 30 May 2020 21:51:26 -0400 Subject: [PATCH 1/2] node pods e2e test: fix leak Signed-off-by: Gaurav Singh --- test/e2e/node/pods.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/node/pods.go b/test/e2e/node/pods.go index 8f926d1d2057f..68f47b02a1780 100644 --- a/test/e2e/node/pods.go +++ b/test/e2e/node/pods.go @@ -272,7 +272,7 @@ var _ = SIGDescribe("Pods Extended", func() { // create the pod, capture the change events, then delete the pod start := time.Now() created := podClient.Create(pod) - ch := make(chan []watch.Event) + ch := make(chan []watch.Event, 1) go func() { defer close(ch) w, err := podClient.Watch(context.TODO(), metav1.ListOptions{ From ccf8ad75e9182ec167a7f76ef2ad3d838aaa6ef7 Mon Sep 17 00:00:00 2001 From: Gaurav Singh Date: Sat, 11 Jul 2020 14:54:34 -0400 Subject: [PATCH 2/2] call watch.Stop() for pending events Signed-off-by: Gaurav Singh --- test/e2e/node/pods.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/e2e/node/pods.go b/test/e2e/node/pods.go index 68f47b02a1780..f2714beb6bf51 100644 --- a/test/e2e/node/pods.go +++ b/test/e2e/node/pods.go @@ -272,7 +272,8 @@ var _ = SIGDescribe("Pods Extended", func() { // create the pod, capture the change events, then delete the pod start := time.Now() created := podClient.Create(pod) - ch := make(chan []watch.Event, 1) + ch := make(chan []watch.Event) + numEvents := 0 go func() { defer close(ch) w, err := podClient.Watch(context.TODO(), metav1.ListOptions{ @@ -298,6 +299,7 @@ var _ = SIGDescribe("Pods Extended", func() { } } ch <- events + numEvents = len(events) }() t := time.Duration(rand.Intn(delay)) * time.Millisecond @@ -319,6 +321,11 @@ var _ = SIGDescribe("Pods Extended", func() { } case <-time.After(5 * time.Minute): framework.Failf("timed out waiting for watch events for %s", pod.Name) + // Iterate over the events and stop them to avoid leak + for i := 0; i < numEvents; i++ { + w := <-ch + w.Stop() + } } end := time.Now()