Skip to content

Commit b93c55c

Browse files
AlliBalliBabahenderkes
authored andcommitted
tests: make caddy_tests faster (php#1823)
1 parent c587ef7 commit b93c55c

3 files changed

Lines changed: 24 additions & 17 deletions

File tree

caddy/caddy_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ func TestMaxWaitTimeWorker(t *testing.T) {
989989
wg.Add(10)
990990
for range 10 {
991991
go func() {
992-
statusCode := getStatusCode("http://localhost:"+testPort+"/sleep.php?sleep=10000&iteration=1", t)
992+
statusCode := getStatusCode("http://localhost:"+testPort+"/sleep.php?sleep=10&iteration=1", t)
993993
if statusCode == http.StatusGatewayTimeout {
994994
success.Store(true)
995995
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package phpheaders
2+
3+
import (
4+
"net/http/httptest"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestAllCommonHeadersAreCorrect(t *testing.T) {
11+
fakeRequest := httptest.NewRequest("GET", "http://localhost", nil)
12+
13+
for header, phpHeader := range CommonRequestHeaders {
14+
// verify that common and uncommon headers return the same result
15+
expectedPHPHeader := GetUnCommonHeader(header)
16+
assert.Equal(t, phpHeader+"\x00", expectedPHPHeader, "header is not well formed: "+phpHeader)
17+
18+
// net/http will capitalize lowercase headers, verify that headers are capitalized
19+
fakeRequest.Header.Add(header, "foo")
20+
_, ok := fakeRequest.Header[header]
21+
assert.True(t, ok, "header is not correctly capitalized: "+header)
22+
}
23+
}

phpmainthread_test.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"testing"
1313
"time"
1414

15-
"github.com/dunglas/frankenphp/internal/phpheaders"
1615
"github.com/stretchr/testify/assert"
1716
)
1817

@@ -150,21 +149,6 @@ func TestTransitionThreadsWhileDoingRequests(t *testing.T) {
150149
Shutdown()
151150
}
152151

153-
// Note: this test is here since it would break compilation when put into the phpheaders package
154-
func TestAllCommonHeadersAreCorrect(t *testing.T) {
155-
fakeRequest := httptest.NewRequest("GET", "http://localhost", nil)
156-
157-
for header, phpHeader := range phpheaders.CommonRequestHeaders {
158-
// verify that common and uncommon headers return the same result
159-
expectedPHPHeader := phpheaders.GetUnCommonHeader(header)
160-
assert.Equal(t, phpHeader+"\x00", expectedPHPHeader, "header is not well formed: "+phpHeader)
161-
162-
// net/http will capitalize lowercase headers, verify that headers are capitalized
163-
fakeRequest.Header.Add(header, "foo")
164-
_, ok := fakeRequest.Header[header]
165-
assert.True(t, ok, "header is not correctly capitalized: "+header)
166-
}
167-
}
168152
func TestFinishBootingAWorkerScript(t *testing.T) {
169153
workers = nil
170154
logger = slog.New(slog.NewTextHandler(io.Discard, nil))

0 commit comments

Comments
 (0)