From 45403fd97aea540e56dfd2c1aa335fed751768d0 Mon Sep 17 00:00:00 2001 From: hugoShaka Date: Mon, 23 Jun 2025 11:30:44 -0400 Subject: [PATCH] Fix flaky `TestServer_generateAgentVersionReport` --- lib/auth/agent_version_report_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/auth/agent_version_report_test.go b/lib/auth/agent_version_report_test.go index edd85d28b6fa1..40e0d8a57a8a4 100644 --- a/lib/auth/agent_version_report_test.go +++ b/lib/auth/agent_version_report_test.go @@ -257,6 +257,14 @@ func TestServer_generateAgentVersionReport(t *testing.T) { UpdaterInfo: &types.UpdaterV2Info{UpdaterStatus: status, UpdateGroup: fixture.updateGroup}, }) if fixture.goodbye != nil { + // Sending the message twice is a little hack to make sure that the auth received the goodbye at + // least once. Else, the auth might still be in the small frame when it received the message + // over the channel but has not stored it yet. When this happens the test becomes flaky. + // Ideally we would peek into the inventory internals and wait for the goodbye to be stored, + // but we don't have access to inventory's private field. + // Because the channel is not buffered and a single go routine is reading on the other side, we know + // that the routine is done processing the first messages if we can send the second. + stream.fakeMsg(fixture.goodbye) stream.fakeMsg(fixture.goodbye) } t.Cleanup(stream.close)