Skip to content

Commit b8fd528

Browse files
authored
Merge branch 'dunglas:main' into ts/wait-time
2 parents 3e799bf + 1d74b2c commit b8fd528

16 files changed

Lines changed: 739 additions & 116 deletions

.github/workflows/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
- name: Run integrations tests
6969
run: ./reload_test.sh
7070
- name: Lint Go code
71-
uses: golangci/golangci-lint-action@v7
71+
uses: golangci/golangci-lint-action@v8
7272
if: matrix.php-versions == '8.4'
7373
with:
7474
version: latest

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ You can also run command-line scripts with:
4343
frankenphp php-cli /path/to/your/script.php
4444
```
4545

46-
> ![WARNING]
46+
> [!WARNING]
4747
>
4848
> In production, prefer using [the Docker images](#docker), [the Brew package](#homebrew)
4949
> or [compiling FrankenPHP from sources](https://frankenphp.dev/docs/compile/).

build-static.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@ if [ -z "${SPC_OPT_BUILD_ARGS}" ]; then
4646
fi
4747
# init spc download additional args
4848
if [ -z "${SPC_OPT_DOWNLOAD_ARGS}" ]; then
49+
SPC_OPT_DOWNLOAD_ARGS="--ignore-cache-sources=php-src --retry 5"
4950
if [ "${SPC_LIBC}" = "musl" ]; then
50-
SPC_OPT_DOWNLOAD_ARGS="--prefer-pre-built --ignore-cache-sources=php-src"
51-
else
52-
SPC_OPT_DOWNLOAD_ARGS="--ignore-cache-sources=php-src"
51+
SPC_OPT_DOWNLOAD_ARGS="${SPC_OPT_DOWNLOAD_ARGS} --prefer-pre-built"
5352
fi
5453
fi
5554
# if we need debug symbols, disable strip

caddy/admin_test.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package caddy_test
22

33
import (
4+
"bytes"
45
"encoding/json"
6+
"fmt"
7+
"github.com/dunglas/frankenphp/internal/fastabs"
58
"io"
69
"net/http"
710
"sync"
@@ -213,3 +216,82 @@ func getDebugState(t *testing.T, tester *caddytest.Tester) frankenphp.FrankenPHP
213216

214217
return debugStates
215218
}
219+
220+
func TestAddModuleWorkerViaAdminApi(t *testing.T) {
221+
// Initialize a server with admin API enabled
222+
tester := caddytest.NewTester(t)
223+
tester.InitServer(`
224+
{
225+
skip_install_trust
226+
admin localhost:2999
227+
http_port `+testPort+`
228+
229+
frankenphp
230+
}
231+
232+
localhost:`+testPort+` {
233+
route {
234+
root ../testdata
235+
php
236+
}
237+
}
238+
`, "caddyfile")
239+
240+
// Get initial debug state to check number of workers
241+
initialDebugState := getDebugState(t, tester)
242+
initialWorkerCount := 0
243+
for _, thread := range initialDebugState.ThreadDebugStates {
244+
if thread.Name != "" && thread.Name != "ready" {
245+
initialWorkerCount++
246+
}
247+
}
248+
249+
// Create a Caddyfile configuration with a module worker
250+
workerConfig := `
251+
{
252+
skip_install_trust
253+
admin localhost:2999
254+
http_port ` + testPort + `
255+
256+
frankenphp
257+
}
258+
259+
localhost:` + testPort + ` {
260+
route {
261+
root ../testdata
262+
php {
263+
worker ../testdata/worker-with-counter.php 1
264+
}
265+
}
266+
}
267+
`
268+
269+
// Send the configuration to the admin API
270+
adminUrl := "http://localhost:2999/load"
271+
r, err := http.NewRequest("POST", adminUrl, bytes.NewBufferString(workerConfig))
272+
assert.NoError(t, err)
273+
r.Header.Set("Content-Type", "text/caddyfile")
274+
resp := tester.AssertResponseCode(r, http.StatusOK)
275+
defer resp.Body.Close()
276+
277+
// Get the updated debug state to check if the worker was added
278+
updatedDebugState := getDebugState(t, tester)
279+
updatedWorkerCount := 0
280+
workerFound := false
281+
filename, _ := fastabs.FastAbs("../testdata/worker-with-counter.php")
282+
for _, thread := range updatedDebugState.ThreadDebugStates {
283+
if thread.Name != "" && thread.Name != "ready" {
284+
updatedWorkerCount++
285+
if thread.Name == "Worker PHP Thread - "+filename {
286+
workerFound = true
287+
}
288+
}
289+
}
290+
291+
// Assert that the worker was added
292+
assert.Greater(t, updatedWorkerCount, initialWorkerCount, "Worker count should have increased")
293+
assert.True(t, workerFound, fmt.Sprintf("Worker with name %q should be found", "Worker PHP Thread - "+filename))
294+
295+
// Make a request to the worker to verify it's working
296+
tester.AssertGetResponse("http://localhost:"+testPort+"/worker-with-counter.php", http.StatusOK, "requests:1")
297+
}

0 commit comments

Comments
 (0)