Skip to content

Commit 644bb5d

Browse files
committed
test: fix flaky TestAddModuleWorkerViaAdminApi
The test POSTs a full config to the admin /load endpoint, which swaps the HTTP listener for the new config, then immediately GETs the newly added worker. A request racing that swap can hit a reset connection (EOF) before the worker ever sees it, as seen on CI (#2604 CI run, and previously on #2412/#2381 per #2413 for the sibling autoscale tests). Retry only on connection-level errors, not on the request itself: once a request reaches the worker it always increments its counter, so retrying past that point would break the "requests:1" assertion.
1 parent 6845134 commit 644bb5d

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

caddy/admin_test.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010
"sync"
1111
"testing"
12+
"time"
1213

1314
"github.com/dunglas/frankenphp/internal/fastabs"
1415

@@ -345,6 +346,24 @@ func TestAddModuleWorkerViaAdminApi(t *testing.T) {
345346
assert.Greater(t, updatedWorkerCount, initialWorkerCount, "Worker count should have increased")
346347
assert.True(t, workerFound, fmt.Sprintf("Worker with name %q should be found", "Worker PHP Thread - "+filename))
347348

348-
// Make a request to the worker to verify it's working
349-
tester.AssertGetResponse("http://localhost:"+testPort+"/worker-with-counter.php", http.StatusOK, "requests:1")
349+
// The /load above swaps the HTTP listener for the new config; a request
350+
// racing that swap can see a reset connection before the worker ever
351+
// receives it, so retry on connection-level failures only (a request
352+
// that reaches the worker always counts, so retrying past that point
353+
// would throw off the "requests:1" assertion below).
354+
workerURL := "http://localhost:" + testPort + "/worker-with-counter.php"
355+
var getResp *http.Response
356+
for i := 0; i < 20; i++ {
357+
getResp, err = http.Get(workerURL)
358+
if err == nil {
359+
break
360+
}
361+
time.Sleep(50 * time.Millisecond)
362+
}
363+
require.NoError(t, err)
364+
defer func() { require.NoError(t, getResp.Body.Close()) }()
365+
body, err := io.ReadAll(getResp.Body)
366+
require.NoError(t, err)
367+
assert.Equal(t, http.StatusOK, getResp.StatusCode)
368+
assert.Equal(t, "requests:1", string(body))
350369
}

0 commit comments

Comments
 (0)