Enhance test reliability by closing SafeWriter before buffer read

- Add calls to `CloseSafeWriter` in `TestJsValueSendVsSendStream` to ensure all pending async writes are flushed before reading the output buffer. This change addresses potential issues with empty buffers on slow CI runners, improving test consistency.
This commit is contained in:
Max 2026-02-11 16:03:21 +08:00
parent 69a6a43362
commit 1b028abdef

View file

@ -1276,6 +1276,11 @@ func TestJsValueSendVsSendStream(t *testing.T) {
t.Fatalf("Call failed: %v", err)
}
// Close SafeWriter to flush all pending async writes before reading buffer.
// SafeWriter processes writes in a background goroutine via channel;
// without this, the buffer may still be empty on slow CI runners.
cxt.CloseSafeWriter()
output := mockWriter.buffer.String()
assert.Contains(t, output, "message_start", "Send should emit message_start")
assert.Contains(t, output, "message_end", "Send should auto-emit message_end")
@ -1300,6 +1305,9 @@ func TestJsValueSendVsSendStream(t *testing.T) {
t.Fatalf("Call failed: %v", err)
}
// Close SafeWriter to flush all pending async writes before reading buffer.
cxt.CloseSafeWriter()
output := mockWriter.buffer.String()
assert.Contains(t, output, "message_start", "SendStream should emit message_start")
assert.NotContains(t, output, "message_end", "SendStream should NOT auto-emit message_end")