From 8854924e65a87052396dc318d1eb683acde664f0 Mon Sep 17 00:00:00 2001 From: a1k24 Date: Mon, 28 Sep 2020 01:06:56 +0530 Subject: [PATCH 1/2] fixes test/integration/ttlcontroller staticcheck --- hack/.staticcheck_failures | 1 - .../ttlcontroller/ttlcontroller_test.go | 34 +++++++++++++++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/hack/.staticcheck_failures b/hack/.staticcheck_failures index c85de44fc73..3c063364519 100644 --- a/hack/.staticcheck_failures +++ b/hack/.staticcheck_failures @@ -7,7 +7,6 @@ test/integration/examples test/integration/framework test/integration/garbagecollector test/integration/scheduler_perf -test/integration/ttlcontroller vendor/k8s.io/apimachinery/pkg/api/apitesting/roundtrip vendor/k8s.io/apimachinery/pkg/api/meta vendor/k8s.io/apimachinery/pkg/apis/meta/v1/validation diff --git a/test/integration/ttlcontroller/ttlcontroller_test.go b/test/integration/ttlcontroller/ttlcontroller_test.go index 1952a99c8c6..4e07ffee7d6 100644 --- a/test/integration/ttlcontroller/ttlcontroller_test.go +++ b/test/integration/ttlcontroller/ttlcontroller_test.go @@ -51,6 +51,7 @@ func createClientAndInformers(t *testing.T, server *httptest.Server) (*clientset func createNodes(t *testing.T, client *clientset.Clientset, startIndex, endIndex int) { var wg sync.WaitGroup + errs := make(chan error, endIndex-startIndex) for i := startIndex; i < endIndex; i++ { wg.Add(1) go func(idx int) { @@ -60,27 +61,48 @@ func createNodes(t *testing.T, client *clientset.Clientset, startIndex, endIndex Name: fmt.Sprintf("node-%d", idx), }, } - if _, err := client.CoreV1().Nodes().Create(context.TODO(), node, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create node: %v", err) + _, err := client.CoreV1().Nodes().Create(context.TODO(), node, metav1.CreateOptions{}) + if err != nil { + errs <- err } }(i) } - wg.Wait() + + go func() { // wait in another go-routine to close channel + wg.Wait() + close(errs) + }() + + for err := range errs { + t.Fatalf("Failed to create node: %v", err) + } } func deleteNodes(t *testing.T, client *clientset.Clientset, startIndex, endIndex int) { var wg sync.WaitGroup + errs := make(chan error, endIndex-startIndex) for i := startIndex; i < endIndex; i++ { wg.Add(1) go func(idx int) { defer wg.Done() name := fmt.Sprintf("node-%d", idx) - if err := client.CoreV1().Nodes().Delete(context.TODO(), name, metav1.DeleteOptions{}); err != nil { - t.Fatalf("Failed to delete node: %v", err) + err := client.CoreV1().Nodes().Delete(context.TODO(), name, metav1.DeleteOptions{}) + if err != nil { + errs <- err } }(i) } - wg.Wait() + + go func() { // wait in another go-routine to close channel + wg.Wait() + close(errs) + }() + + for err := range errs { + if err != nil { + t.Fatalf("Failed to delete node: %v", err) + } + } } func waitForNodesWithTTLAnnotation(t *testing.T, nodeLister listers.NodeLister, numNodes, ttlSeconds int) { From b3d43207e83e99d940a3567a39d6fbbcb88ee614 Mon Sep 17 00:00:00 2001 From: a1k24 Date: Wed, 30 Sep 2020 11:53:46 +0530 Subject: [PATCH 2/2] resolve PR comment ( add nil check ) --- test/integration/ttlcontroller/ttlcontroller_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/integration/ttlcontroller/ttlcontroller_test.go b/test/integration/ttlcontroller/ttlcontroller_test.go index 4e07ffee7d6..31cd74a2c1c 100644 --- a/test/integration/ttlcontroller/ttlcontroller_test.go +++ b/test/integration/ttlcontroller/ttlcontroller_test.go @@ -74,7 +74,9 @@ func createNodes(t *testing.T, client *clientset.Clientset, startIndex, endIndex }() for err := range errs { - t.Fatalf("Failed to create node: %v", err) + if err != nil { + t.Fatalf("Failed to create node: %v", err) + } } }