Skip to content

Commit

Permalink
Fix #46
Browse files Browse the repository at this point in the history
  This is the bare minimum required to make fibers work within the go
  runtime.
  • Loading branch information
krakjoe authored and dunglas committed Jan 14, 2024
1 parent 00b1d0e commit 530abea
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
17 changes: 17 additions & 0 deletions frankenphp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,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)
Expand Down
9 changes: 9 additions & 0 deletions testdata/fiber-basic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
require_once __DIR__.'/_executor.php';

return function() {
$fiber = new Fiber(function() {
echo 'Fiber '.($_GET['i'] ?? '');
});
$fiber->start();
};

0 comments on commit 530abea

Please sign in to comment.