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