From 4d3ba022ce27b7421c71df2c323c3673fa7f6a6c Mon Sep 17 00:00:00 2001 From: Julian Sommer <115516918+juliansommer@users.noreply.github.com> Date: Thu, 3 Sep 2026 16:23:35 +1000 Subject: [PATCH] fix: poll for the outcome point instead of racing the reply natsMetricsHandler records after the handler has already replied, so a test that collects the moment nc.Request returns can beat the point to the reader. Matches the poll the ec2.cmd outcome tests already use. --- spinifex/daemon/nats_outcome_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spinifex/daemon/nats_outcome_test.go b/spinifex/daemon/nats_outcome_test.go index bd629099d..b76b44323 100644 --- a/spinifex/daemon/nats_outcome_test.go +++ b/spinifex/daemon/nats_outcome_test.go @@ -145,6 +145,12 @@ func TestHandleNATSRequestReportsOutcome(t *testing.T) { _, err = nc.Request(tc.subject, reqData, 5*time.Second) require.NoError(t, err) + // The handler records after it replies, so poll rather than assume the + // point has landed by the time the reply arrives. + require.Eventually(t, func() bool { + return len(requestOutcomesFor(t, tc.subject)) > 0 + }, 5*time.Second, 20*time.Millisecond, "the handler must record its point") + assert.Equal(t, []string{tc.want}, requestOutcomesFor(t, tc.subject)) }) } @@ -173,6 +179,12 @@ func TestHandleNATSRequestReportsOutcomeForBadPayload(t *testing.T) { _, err = nc.Request(subject, []byte("{not json"), 5*time.Second) require.NoError(t, err) + // The handler records after it replies, so poll rather than assume the point + // has landed by the time the reply arrives. + require.Eventually(t, func() bool { + return len(requestOutcomesFor(t, subject)) > 0 + }, 5*time.Second, 20*time.Millisecond, "the handler must record its point") + assert.Equal(t, []string{outcomeClientError}, requestOutcomesFor(t, subject)) }