From 7514c0888913f8f1e5f77c28c5ae85a3cb06469a Mon Sep 17 00:00:00 2001 From: michael mccune Date: Mon, 9 Oct 2023 15:07:25 -0400 Subject: [PATCH 1/2] update bad url endpoint termination handler test This change moves the bad url test to its own `Context` block so that it does not get caught in the mock termination service counter. In some cases it is possible for the bad url test to be run first, when this happens the counter will never advance because the url is not valid. This produces a dead lock condition in the test. Migrating the test to its own block alleviates this issue. --- pkg/termination/termination_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/termination/termination_test.go b/pkg/termination/termination_test.go index fbd854334..d21f0dc15 100644 --- a/pkg/termination/termination_test.go +++ b/pkg/termination/termination_test.go @@ -169,7 +169,9 @@ var _ = Describe("Handler Suite", func() { Consistently(nodeMarkedForDeletion(testNode.Name)).Should(BeFalse()) }) }) + }) + Context("when the termination endpoint is invalid", func() { Context("and the poll URL cannot be reached", func() { BeforeEach(func() { h.pollURL = &url.URL{Opaque: "abc#1://localhost"} From bdce80820aa92b816dd7075e369ebe77b66434d2 Mon Sep 17 00:00:00 2001 From: michael mccune Date: Mon, 9 Oct 2023 16:00:44 -0400 Subject: [PATCH 2/2] update instance termination not fulfilled test This test can be affected by the order of the tests being run and the shared counter variable to record requests to the mock endpointer server. The fix adds a reset to the counter and a special handler to increase count. --- pkg/termination/termination_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/termination/termination_test.go b/pkg/termination/termination_test.go index d21f0dc15..3f6c1595d 100644 --- a/pkg/termination/termination_test.go +++ b/pkg/termination/termination_test.go @@ -122,6 +122,7 @@ var _ = Describe("Handler Suite", func() { var counter int32 BeforeEach(func() { + counter = 0 // Ensure the polling logic is excercised in tests httpHandler = newMockHTTPHandler(func(rw http.ResponseWriter, req *http.Request) { if atomic.LoadInt32(&counter) == 4 { @@ -162,7 +163,10 @@ var _ = Describe("Handler Suite", func() { Context("and the instance termination notice is not fulfilled", func() { BeforeEach(func() { - httpHandler = newMockHTTPHandler(notPreempted) + httpHandler = newMockHTTPHandler(func(rw http.ResponseWriter, req *http.Request) { + atomic.AddInt32(&counter, 1) + notPreempted(rw, req) + }) }) It("should not mark the node for deletion", func() {