mirror of
https://github.com/dunglas/frankenphp
synced 2024-11-23 08:39:21 +00:00
Fix #46
This is the bare minimum required to make fibers work within the go runtime.
This commit is contained in:
parent
a6572225f6
commit
799a9d5cb1
@ -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
9
testdata/fiber-basic.php
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
require_once __DIR__.'/_executor.php';
|
||||
|
||||
return function() {
|
||||
$fiber = new Fiber(function() {
|
||||
echo 'Fiber '.($_GET['i'] ?? '');
|
||||
});
|
||||
$fiber->start();
|
||||
};
|
Loading…
Reference in New Issue
Block a user