Files
graphql-monitoring-proxy/coalesced_snapshot_test.go
T
lukaszraczylo e2af5b079f fix(coalesce): copy the primary response body for waiters
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.
2026-11-03 00:02:15 +00:00

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