Compare commits

...

3 Commits

Author SHA1 Message Date
Kévin Dunglas
c2524a5022 fix test 2023-12-18 14:02:35 +01:00
Kévin Dunglas
0048f84741 some fixes 2023-12-18 14:02:35 +01:00
Kévin Dunglas
7cc7d661f9 test: many concurrent reload requests 2023-12-18 14:02:35 +01:00
2 changed files with 59 additions and 2 deletions

View File

@@ -9,6 +9,8 @@ import (
"testing"
"github.com/caddyserver/caddy/v2/caddytest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestPHP(t *testing.T) {
@@ -37,8 +39,9 @@ func TestPHP(t *testing.T) {
wg.Add(1)
go func(i int) {
defer wg.Done()
tester.AssertGetResponse(fmt.Sprintf("http://localhost:9080/index.php?i=%d", i), http.StatusOK, fmt.Sprintf("I am by birth a Genevese (%d)", i))
wg.Done()
}(i)
}
wg.Wait()
@@ -102,8 +105,9 @@ func TestWorker(t *testing.T) {
wg.Add(1)
go func(i int) {
defer wg.Done()
tester.AssertGetResponse(fmt.Sprintf("http://localhost:9080/index.php?i=%d", i), http.StatusOK, fmt.Sprintf("I am by birth a Genevese (%d)", i))
wg.Done()
}(i)
}
wg.Wait()
@@ -189,3 +193,53 @@ func TestPHPServerDirectiveDisableFileServer(t *testing.T) {
tester.AssertGetResponse("http://localhost:9080", http.StatusOK, "I am by birth a Genevese (i not set)")
tester.AssertGetResponse("http://localhost:9080/hello.txt", http.StatusNotFound, "Not found")
}
// TestReload sends many concurrent reload requests, as done by Laravel Octane.
// Better run this test with -race.
func TestReload(t *testing.T) {
tester := caddytest.NewTester(t)
tester.InitServer(`
{
skip_install_trust
admin localhost:2999
http_port 9080
https_port 9443
frankenphp {
worker ../testdata/index.php
}
order php_server before respond
}
localhost:9080 {
root * ../testdata
php_server
}
`, "caddyfile")
const configURL = "http://localhost:2999/config/apps/frankenphp"
var wg sync.WaitGroup
for i := 0; i < 20; i++ {
wg.Add(1)
go func() {
defer wg.Done()
resp1, err := tester.Client.Get(configURL)
require.NoError(t, err)
r, err := http.NewRequest("PATCH", configURL, resp1.Body)
require.NoError(t, err)
r.Header.Add("Content-Type", "application/json")
r.Header.Add("Cache-Control", "must-revalidate")
resp, err := tester.Client.Do(r)
require.NoError(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode)
}()
}
wg.Wait()
tester.AssertGetResponse("http://localhost:9080", http.StatusOK, "I am by birth a Genevese (i not set)")
}

View File

@@ -13,6 +13,7 @@ require (
github.com/dunglas/mercure/caddy v0.15.6
github.com/dunglas/vulcain/caddy v1.0.0
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.8.4
go.uber.org/automaxprocs v1.5.3
go.uber.org/zap v1.26.0
)
@@ -37,6 +38,7 @@ require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dgraph-io/badger v1.6.2 // indirect
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
@@ -113,6 +115,7 @@ require (
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.17.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect