Skip to content

Commit 65abcbb

Browse files
authored
test: stop autoscale tests from hanging on request failure (#2413)
`TestAutoScaleRegularThreadsOnAutomaticThreadLimit` (and its sibling `TestAutoScaleWorkerThreads`) in `caddy/admin_test.go` would burn the package-wide 10 minute Go test timeout whenever the PHP server returned a connection error during the load loop. This was observed on the PHP 8.5 / Linux CI matrix on #2412 (and on #2381 for the related `TestAddModuleWorkerViaAdminApi`). Root cause: `caddytest.AssertGetResponse` calls `t.Fatalf` on connection errors. From a non-test goroutine that triggers `runtime.Goexit`, which skips the plain `wg.Done()` after it, so `wg.Wait()` blocks forever and the retry loop never gets to check `amountOfThreads` or break out. Two surgical changes: - `defer wg.Done()` so a `Fatalf`'d goroutine still decrements the WaitGroup. - Break out of the retry loop once `t.Failed()` is true so we don't keep hammering an already-broken server for another 9 rounds. Net diff: +6 / -2 lines per test, no new imports.
1 parent 6ae610c commit 65abcbb

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)