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.
This commit is contained in:
Julian Sommer
2026-09-03 16:23:35 +10:00
parent d9593c0a48
commit 4d3ba022ce
+12
View File
@@ -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))
}