From 2167bbff05b62e72f928e4a2957931460e6bfabe Mon Sep 17 00:00:00 2001 From: Ravishankar Date: Thu, 19 Dec 2024 21:49:03 +0530 Subject: [PATCH] Fix the flaky failure --- internal/component/faro/receiver/receiver_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/component/faro/receiver/receiver_test.go b/internal/component/faro/receiver/receiver_test.go index 1199ee170..3c987b665 100644 --- a/internal/component/faro/receiver/receiver_test.go +++ b/internal/component/faro/receiver/receiver_test.go @@ -135,6 +135,7 @@ func Test(t *testing.T) { defer resp.Body.Close() require.Equal(t, http.StatusAccepted, resp.StatusCode) + lr.wg.Wait() // Wait for the fakelogreceiver goroutine to process require.Len(t, lr.GetEntries(), 1) require.Equal(t, tc.expect, lr.entries[0]) @@ -146,6 +147,7 @@ type fakeLogsReceiver struct { ch chan loki.Entry entriesMut sync.RWMutex + wg sync.WaitGroup entries []loki.Entry } @@ -158,6 +160,7 @@ func newFakeLogsReceiver(t *testing.T) *fakeLogsReceiver { ch: make(chan loki.Entry, 1), } + lr.wg.Add(1) go func() { defer close(lr.ch) @@ -175,6 +178,7 @@ func newFakeLogsReceiver(t *testing.T) *fakeLogsReceiver { }, }) lr.entriesMut.Unlock() + lr.wg.Done() } }()