From f3619f04f115177d4ca9c06e2a428d053794fb9e Mon Sep 17 00:00:00 2001 From: Yang Li Date: Sun, 18 Nov 2018 17:40:35 +0800 Subject: [PATCH] Call cancel functions to avoid context leaks Kubernetes-commit: 8dc9619d44ce2074696a4036b2acdc21f3cd0662 --- tools/watch/until_test.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/watch/until_test.go b/tools/watch/until_test.go index dd055946..0243beeb 100644 --- a/tools/watch/until_test.go +++ b/tools/watch/until_test.go @@ -53,7 +53,9 @@ func TestUntil(t *testing.T) { func(event watch.Event) (bool, error) { return event.Type == watch.Modified, nil }, } - ctx, _ := context.WithTimeout(context.Background(), time.Minute) + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + defer cancel() + lastEvent, err := UntilWithoutRetry(ctx, fw, conditions...) if err != nil { t.Fatalf("expected nil error, got %#v", err) @@ -80,7 +82,9 @@ func TestUntilMultipleConditions(t *testing.T) { func(event watch.Event) (bool, error) { return event.Type == watch.Added, nil }, } - ctx, _ := context.WithTimeout(context.Background(), time.Minute) + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + defer cancel() + lastEvent, err := UntilWithoutRetry(ctx, fw, conditions...) if err != nil { t.Fatalf("expected nil error, got %#v", err) @@ -108,7 +112,9 @@ func TestUntilMultipleConditionsFail(t *testing.T) { func(event watch.Event) (bool, error) { return event.Type == watch.Deleted, nil }, } - ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + lastEvent, err := UntilWithoutRetry(ctx, fw, conditions...) if err != wait.ErrWaitTimeout { t.Fatalf("expected ErrWaitTimeout error, got %#v", err) @@ -169,6 +175,7 @@ func TestUntilErrorCondition(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() + _, err := UntilWithoutRetry(ctx, fw, conditions...) if err == nil { t.Fatal("expected an error")