This is the bare minimum required to make fibers work within the go
  runtime.
This commit is contained in:
Joe Watkins 2022-11-10 06:44:52 +01:00 committed by Kévin Dunglas
parent a6572225f6
commit 799a9d5cb1
No known key found for this signature in database
GPG Key ID: 4D04EBEF06AAF3A6
2 changed files with 26 additions and 0 deletions

View File

@ -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)

9
testdata/fiber-basic.php vendored Normal file
View File

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