Browse Source

Adds fibers test back in.

Alliballibaba 3 months ago
parent
commit
ecce5d52b4
2 changed files with 26 additions and 0 deletions
  1. 17 0
      frankenphp_test.go
  2. 9 0
      testdata/fiber-basic.php

+ 17 - 0
frankenphp_test.go

@@ -592,6 +592,23 @@ func testFiberNoCgo(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)
+}
+
 func TestRequestHeaders_module(t *testing.T) { testRequestHeaders(t, &testOptions{}) }
 func TestRequestHeaders_worker(t *testing.T) {
 	testRequestHeaders(t, &testOptions{workerScript: "request-headers.php"})

+ 9 - 0
testdata/fiber-basic.php

@@ -0,0 +1,9 @@
+<?php
+require_once __DIR__.'/_executor.php';
+
+return function() {
+    $fiber = new Fiber(function() {
+        echo 'Fiber '.($_GET['i'] ?? '');
+    });
+    $fiber->start();
+};