From 9133c48fdb24a6735f0c11ca07d5ddaf7fba55d4 Mon Sep 17 00:00:00 2001 From: Julian Sommer <115516918+juliansommer@users.noreply.github.com> Date: Thu, 27 Aug 2026 16:02:26 +1000 Subject: [PATCH] fix: wait for the EC2 command outcome instead of racing the handler The handler records its request point after it replies, so asserting as soon as Request returns could read the metric before it landed. Poll for the outcome the way the sibling drain test does. --- spinifex/daemon/nats_classification_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spinifex/daemon/nats_classification_test.go b/spinifex/daemon/nats_classification_test.go index 200b0e95c..6ed9744b2 100644 --- a/spinifex/daemon/nats_classification_test.go +++ b/spinifex/daemon/nats_classification_test.go @@ -8,6 +8,7 @@ import ( "log/slog" "net/http" "reflect" + "slices" "testing" "time" @@ -177,7 +178,11 @@ func TestEC2CommandRecordsUnderTheCommandNotTheInstance(t *testing.T) { _, err = daemon.natsConn.Request(subject, data, 5*time.Second) require.NoError(t, err) - assert.Contains(t, requestOutcomesFor(t, ec2CmdAction("StopInstance")), outcomeClientError, + // 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 slices.Contains(requestOutcomesFor(t, ec2CmdAction("StopInstance")), outcomeClientError) + }, 5*time.Second, 20*time.Millisecond, "a stop naming an instance this node does not hold is the caller's error, and must be counted") assert.Empty(t, requestOutcomesFor(t, subject), "the instance id must not reach the metric dimension")