From 349c79fd96a86d376a0c28000e4cd76de644c80f Mon Sep 17 00:00:00 2001 From: Dylan Myers Date: Thu, 30 Jul 2026 09:30:33 -0400 Subject: [PATCH] chore(tests): poll received data in udp output tests instead of sleeping (PIPE-986) Assisted-by: Claude Opus 4.8 --- output/udp/udp_test.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/output/udp/udp_test.go b/output/udp/udp_test.go index 2f34414..035ee62 100644 --- a/output/udp/udp_test.go +++ b/output/udp/udp_test.go @@ -9,6 +9,7 @@ import ( "time" "github.com/observiq/blitz/output" + "github.com/stretchr/testify/require" "go.uber.org/zap" ) @@ -178,17 +179,23 @@ func TestUDP_Integration(t *testing.T) { t.Errorf("First Write() failed: %v", err) } - // Give some time for first message to be sent - time.Sleep(50 * time.Millisecond) - // Send second message err = udp.Write(ctx, output.LogRecord{Message: testData2}) if err != nil { t.Errorf("Second Write() failed: %v", err) } - // Give some time for data to be sent - time.Sleep(100 * time.Millisecond) + // Wait for the server to receive both messages before stopping. Stop closes + // the data channel and cancels the worker context at the same time, so any + // data still buffered can be dropped if we stop before the worker drains it. + require.Eventually(t, func() bool { + var allData []byte + for _, data := range getReceivedUDPData(t) { + allData = append(allData, data...) + } + s := string(allData) + return strings.Contains(s, testData1) && strings.Contains(s, testData2) + }, 5*time.Second, 10*time.Millisecond) // Stop the client err = udp.Stop(ctx) @@ -196,9 +203,6 @@ func TestUDP_Integration(t *testing.T) { t.Errorf("Stop() failed: %v", err) } - // Wait a bit more for final data to arrive - time.Sleep(100 * time.Millisecond) - // Verify the server received the data receivedData := getReceivedUDPData(t)