mirror of
https://github.com/mulgadc/spinifex.git
synced 2026-10-15 09:01:31 +00:00
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:
@@ -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))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user