From 1b028abdef63f5eeca4f7f8a9ba0c35a465dc465 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 11 Feb 2026 16:03:21 +0800 Subject: [PATCH] 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. --- agent/context/jsapi_output_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/agent/context/jsapi_output_test.go b/agent/context/jsapi_output_test.go index 91592ffd..b657addb 100644 --- a/agent/context/jsapi_output_test.go +++ b/agent/context/jsapi_output_test.go @@ -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")