diff --git a/nomad/eval_broker_test.go b/nomad/eval_broker_test.go index 897eee379f9c..0fede6c9f2df 100644 --- a/nomad/eval_broker_test.go +++ b/nomad/eval_broker_test.go @@ -9,14 +9,16 @@ import ( "time" msgpackrpc "github.com/hashicorp/net-rpc-msgpackrpc" + "github.com/shoenig/test" + "github.com/shoenig/test/must" + "github.com/shoenig/test/wait" + "github.com/stretchr/testify/require" + "github.com/hashicorp/nomad/ci" "github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/state" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/testutil" - "github.com/shoenig/test" - "github.com/shoenig/test/must" - "github.com/stretchr/testify/require" ) var ( @@ -1568,15 +1570,26 @@ func TestEvalBroker_IntegrationTest(t *testing.T) { config := DefaultConfig() config.NumSchedulers = 4 config.EvalReapCancelableInterval = time.Minute * 10 - require.NoError(t, srv.Reload(config)) + must.NoError(t, srv.Reload(config)) // assert that all but 2 evals were canceled and that the eval broker state // has been cleared - require.Eventually(t, func() bool { - got := getEvalStatuses() - return got[structs.EvalStatusComplete] == 2 && got[structs.EvalStatusCancelled] == 9 - }, 2*time.Second, time.Millisecond*100) + var got map[string]int + + must.Wait(t, wait.InitialSuccess( + wait.Timeout(10*time.Second), + wait.Gap(100*time.Millisecond), + wait.BoolFunc(func() bool { + got = getEvalStatuses() + return got[structs.EvalStatusComplete] == 2 && + got[structs.EvalStatusCancelled] == 9 + }), + ), + must.Func(func() string { + return fmt.Sprintf("expected [complete:2 canceled:9] within timeout, got: %v", got) + }), + ) must.Eq(t, BrokerStats{TotalReady: 0, TotalUnacked: 0, TotalPending: 0, TotalCancelable: 0}, getStats())