plugin tests: the slow-recall fixture renames its output into place (#6019)

TestGatewayHookSlowRecallUsesConfiguredBudget polls every 50ms for the
file its onResponse writes and fails on the first read that succeeds.
fs.writeFileSync creates the file empty before it writes the bytes, so a
read in between saw "" and failed with `captured ` (mote at f03ec97b8,
and macOS CI run 43664046438 at 01f307091). The fixture now writes a
.tmp beside it and renames it in, so the file appears whole or not at
all. The budgets under test were never the cause: 24.16s is the 12s
recall plus the 12s onResponse.

Run:
- Broken by hand: the fixture opening the file, waiting 300ms, then
  writing goes red the way CI did (`gateway_budget_test.go:53: captured `).
- The fix: -count=3 -run '^TestGatewayHookSlowRecallUsesConfiguredBudget$'
  ok on mote (load 26 on 18 cores at the time), and the whole
  internal/plugin package ok on mica (179s), with go vet and gofmt -l
  clean.

Not run: the full suite; this changes one test's JS fixture only.

Closes #6019.
This commit is contained in:
yetone
2026-11-15 10:43:03 +08:00
parent 705d67efc7
commit ab3bcdb145
+5 -1
View File
@@ -27,7 +27,11 @@ export async function onRequest(body, ctx) {
}
export async function onResponse(reply, ctx) {
await new Promise(resolve => setTimeout(resolve, 12000));
if (!ctx.signal.aborted) fs.writeFileSync(ctx.options.output, JSON.stringify(reply));
if (ctx.signal.aborted) return;
// written beside and renamed in: writeFileSync creates the file empty
// before it writes, and the loop below read it then ("captured ", #6019)
fs.writeFileSync(ctx.options.output + ".tmp", JSON.stringify(reply));
fs.renameSync(ctx.options.output + ".tmp", ctx.options.output);
}`)
if err := SetOptions(spec, map[string]any{"gatewayTimeoutMs": 15000, "output": output}); err != nil {
t.Fatal(err)