mirror of
https://github.com/lukaszraczylo/graphql-monitoring-proxy.git
synced 2026-11-07 08:34:16 +00:00
Waiters read the primary response buffer while fasthttp could reuse it for another request. A waiter could then send the wrong body. The primary now gives waiters their own copy.
28 lines
707 B
Go
28 lines
707 B
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/gofiber/fiber/v3"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/valyala/fasthttp"
|
|
)
|
|
|
|
// Pins theorems/Theorems/CoalesceAlias.lean: waiters never alias the primary's response buffer.
|
|
func TestSnapshotCoalescedResponse_OwnsBody(t *testing.T) {
|
|
app := fiber.New()
|
|
fctx := &fasthttp.RequestCtx{}
|
|
c := app.AcquireCtx(fctx)
|
|
defer app.ReleaseCtx(c)
|
|
|
|
c.Response().SetStatusCode(201)
|
|
c.Response().SetBody([]byte(`{"user":"alice"}`))
|
|
|
|
snap := snapshotCoalescedResponse(c)
|
|
|
|
c.Response().SetBody([]byte(`{"user":"bobby"}`)) // buffer reused by a later request
|
|
|
|
assert.Equal(t, 201, snap.StatusCode)
|
|
assert.Equal(t, `{"user":"alice"}`, string(snap.Body))
|
|
}
|