@@ -420,7 +420,7 @@ func TestLog_error_log_worker(t *testing.T) {
420420 testLog_error_log (t , & testOptions {workerScript : "log-error_log.php" })
421421}
422422func testLog_error_log (t * testing.T , opts * testOptions ) {
423- var buf bytes. Buffer
423+ var buf syncBuffer
424424 opts .logger = slog .New (slog .NewTextHandler (& buf , & slog.HandlerOptions {Level : slog .LevelDebug }))
425425
426426 runTest (t , func (handler func (http.ResponseWriter , * http.Request ), _ * httptest.Server , i int ) {
@@ -437,7 +437,7 @@ func TestLog_frankenphp_log_worker(t *testing.T) {
437437 testLog_frankenphp_log (t , & testOptions {workerScript : "log-frankenphp_log.php" })
438438}
439439func testLog_frankenphp_log (t * testing.T , opts * testOptions ) {
440- var buf bytes. Buffer
440+ var buf syncBuffer
441441
442442 opts .logger = slog .New (slog .NewTextHandler (& buf , & slog.HandlerOptions {Level : slog .LevelDebug }))
443443
@@ -465,7 +465,7 @@ func TestConnectionAbort_worker(t *testing.T) {
465465func testConnectionAbort (t * testing.T , opts * testOptions ) {
466466 testFinish := func (finish string ) {
467467 t .Run (fmt .Sprintf ("finish=%s" , finish ), func (t * testing.T ) {
468- var buf bytes. Buffer
468+ var buf syncBuffer
469469 opts .logger = slog .New (slog .NewTextHandler (& buf , & slog.HandlerOptions {Level : slog .LevelInfo }))
470470
471471 runTest (t , func (handler func (http.ResponseWriter , * http.Request ), _ * httptest.Server , i int ) {
@@ -1078,3 +1078,23 @@ func FuzzRequest(f *testing.F) {
10781078 }, & testOptions {workerScript : "request-headers.php" })
10791079 })
10801080}
1081+
1082+ // SyncBuffer is a thread-safe buffer for capturing logs in tests.
1083+ type syncBuffer struct {
1084+ b bytes.Buffer
1085+ mu sync.RWMutex
1086+ }
1087+
1088+ func (s * syncBuffer ) Write (p []byte ) (n int , err error ) {
1089+ s .mu .Lock ()
1090+ defer s .mu .Unlock ()
1091+
1092+ return s .b .Write (p )
1093+ }
1094+
1095+ func (s * syncBuffer ) String () string {
1096+ s .mu .RLock ()
1097+ defer s .mu .RUnlock ()
1098+
1099+ return s .b .String ()
1100+ }
0 commit comments