From 4a87ad3609a887f56390722a6f9df90d46aa737e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Wed, 5 Oct 2022 15:44:02 +0200 Subject: [PATCH] chore: add tests regarding persistent objects --- frankenphp_test.go | 20 ++++++++++++++++++++ testdata/_executor.php | 2 ++ testdata/persistent-object-require.php | 6 ++++++ testdata/persistent-object.php | 13 +++++++++++++ worker.go | 1 + 5 files changed, 42 insertions(+) create mode 100644 testdata/persistent-object-require.php create mode 100644 testdata/persistent-object.php diff --git a/frankenphp_test.go b/frankenphp_test.go index 2d97550b..46506d20 100644 --- a/frankenphp_test.go +++ b/frankenphp_test.go @@ -294,6 +294,26 @@ func testPhpInfo(t *testing.T, opts *testOptions) { }, opts) } +func TestPersistentObject_module(t *testing.T) { testPersistentObject(t, nil) } +func TestPersistentObject_worker(t *testing.T) { + testPersistentObject(t, &testOptions{workerScript: "persistent-object.php"}) +} +func testPersistentObject(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/persistent-object.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(`request: %d +class exists: 1 +id: obj1 +object id: 1`, i)) + }, opts) +} + func ExampleExecuteScript() { if err := frankenphp.Init(); err != nil { panic(err) diff --git a/testdata/_executor.php b/testdata/_executor.php index fe9062d1..df522ffe 100644 --- a/testdata/_executor.php +++ b/testdata/_executor.php @@ -7,3 +7,5 @@ if (!isset($_SERVER['FRANKENPHP_WORKER'])) { } while (frankenphp_handle_request($fn)) {} + +return; diff --git a/testdata/persistent-object-require.php b/testdata/persistent-object-require.php new file mode 100644 index 00000000..d0ee48ad --- /dev/null +++ b/testdata/persistent-object-require.php @@ -0,0 +1,6 @@ +id . "\n"; + echo 'object id: '. spl_object_id($foo); +}; diff --git a/worker.go b/worker.go index 49a34bb4..e6ace515 100644 --- a/worker.go +++ b/worker.go @@ -64,6 +64,7 @@ func startWorkers(fileName string, nbWorkers int) error { return } + // TODO: check if the termination is expected l.Debug("terminated", zap.String("worker", fileName)) }() }