From 799a9d5cb12b030a4b53928458ad594ea0b4e1bc Mon Sep 17 00:00:00 2001 From: Joe Watkins Date: Thu, 10 Nov 2022 06:44:52 +0100 Subject: [PATCH] Fix #46 This is the bare minimum required to make fibers work within the go runtime. --- frankenphp_test.go | 17 +++++++++++++++++ testdata/fiber-basic.php | 9 +++++++++ 2 files changed, 26 insertions(+) create mode 100644 testdata/fiber-basic.php diff --git a/frankenphp_test.go b/frankenphp_test.go index 2c1e5c6..3e357d9 100644 --- a/frankenphp_test.go +++ b/frankenphp_test.go @@ -496,6 +496,23 @@ func testEarlyHints(t *testing.T, opts *testOptions) { }, opts) } +func TestFiberBasic_module(t *testing.T) { testFiberBasic(t, &testOptions{}) } +func TestFiberBasic_worker(t *testing.T) { + testFiberBasic(t, &testOptions{workerScript: "fiber-basic.php"}) +} +func testFiberBasic(t *testing.T, opts *testOptions) { + runTest(t, func(handler func(http.ResponseWriter, *http.Request), _ *httptest.Server, i int) { + req := httptest.NewRequest("GET", fmt.Sprintf("http://example.com/fiber-basic.php?i=%d", i), nil) + w := httptest.NewRecorder() + handler(w, req) + + resp := w.Result() + body, _ := io.ReadAll(resp.Body) + + assert.Equal(t, string(body), fmt.Sprintf("Fiber %d", i)) + }, opts) +} + type streamResponseRecorder struct { *httptest.ResponseRecorder writeCallback func(buf []byte) diff --git a/testdata/fiber-basic.php b/testdata/fiber-basic.php new file mode 100644 index 0000000..bdb5233 --- /dev/null +++ b/testdata/fiber-basic.php @@ -0,0 +1,9 @@ +start(); +};