Skip to content

Commit cdb0ff7

Browse files
committed
test: stop autoscale tests from hanging on request failure
AssertGetResponse calls t.Fatalf on connection errors which triggers runtime.Goexit and skips the plain wg.Done(), leaving wg.Wait() blocked until the package-wide 10 minute Go test timeout kills every test in caddy/. Defer wg.Done() and bail out of the retry loop once the test is already failed, so the failure surfaces in seconds.
1 parent 6ae610c commit cdb0ff7

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

caddy/admin_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,15 @@ func TestAutoScaleWorkerThreads(t *testing.T) {
162162
wg.Add(requestsPerTry)
163163
for range requestsPerTry {
164164
go func() {
165+
// deferred so a t.Fatalf from a failed request doesn't leak the WaitGroup
166+
defer wg.Done()
165167
tester.AssertGetResponse(endpoint, http.StatusOK, "slept for 2 ms and worked for 1000 iterations")
166-
wg.Done()
167168
}()
168169
}
169170
wg.Wait()
170171

171172
amountOfThreads = getNumThreads(t, tester)
172-
if amountOfThreads > 2 {
173+
if amountOfThreads > 2 || t.Failed() {
173174
break
174175
}
175176
}
@@ -214,14 +215,15 @@ func TestAutoScaleRegularThreadsOnAutomaticThreadLimit(t *testing.T) {
214215
wg.Add(requestsPerTry)
215216
for range requestsPerTry {
216217
go func() {
218+
// deferred so a t.Fatalf from a failed request doesn't leak the WaitGroup
219+
defer wg.Done()
217220
tester.AssertGetResponse(endpoint, http.StatusOK, "slept for 2 ms and worked for 1000 iterations")
218-
wg.Done()
219221
}()
220222
}
221223
wg.Wait()
222224

223225
amountOfThreads = getNumThreads(t, tester)
224-
if amountOfThreads > 1 {
226+
if amountOfThreads > 1 || t.Failed() {
225227
break
226228
}
227229
}

0 commit comments

Comments
 (0)