Skip to content

Commit d8cb917

Browse files
Merge pull request #68 from mresvanis/fix-termination-unit-tests
Fix termination tests randomly timing out
2 parents 97ea122 + 22df817 commit d8cb917

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

pkg/termination/termination_test.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ var _ = Describe("Handler Suite", func() {
124124
var counter int32
125125

126126
BeforeEach(func() {
127+
counter = 0
128+
127129
// Ensure the polling logic is excercised in tests
128130
httpHandler = newMockHTTPHandler(func(rw http.ResponseWriter, req *http.Request) {
129131
if atomic.LoadInt32(&counter) == 4 {
@@ -135,15 +137,15 @@ var _ = Describe("Handler Suite", func() {
135137
})
136138
})
137139

138-
JustBeforeEach(func() {
139-
// Ensure the polling logic is excercised in tests
140-
for atomic.LoadInt32(&counter) < 4 {
141-
continue
142-
}
143-
})
144-
145140
Context("and the handler is stopped", func() {
146141
JustBeforeEach(func() {
142+
// Ensure the polling logic is tested as well
143+
for atomic.LoadInt32(&counter) < 4 {
144+
// use 50ms since polling is set to 100ms
145+
time.Sleep(50 * time.Millisecond)
146+
continue
147+
}
148+
147149
close(stop)
148150
})
149151

@@ -157,6 +159,15 @@ var _ = Describe("Handler Suite", func() {
157159
})
158160

159161
Context("and the instance termination notice is fulfilled", func() {
162+
JustBeforeEach(func() {
163+
// Ensure the polling logic is tested as well
164+
for atomic.LoadInt32(&counter) < 4 {
165+
// use 50ms since polling is set to 100ms
166+
time.Sleep(50 * time.Millisecond)
167+
continue
168+
}
169+
})
170+
160171
It("should mark the node for deletion", func() {
161172
Eventually(nodeMarkedForDeletion(testNode.Name)).Should(BeTrue())
162173
})

0 commit comments

Comments
 (0)