Skip to content

Commit

Permalink
eval broker: extend timeout on integration test
Browse files Browse the repository at this point in the history
Following the update to the go1.20 toolchain, the eval broker integration test
started to become flaky. In order to isolate the problem from the test
infrastructure and reduce test flakiness, update the test to use a longer
timeout and to use `shoenig/test/wait` so we can have sensible reporting of the
results rather than just a timeout error.
  • Loading branch information
tgross committed Feb 9, 2023
1 parent 88cd93b commit 1516fec
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions nomad/eval_broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 1516fec

Please sign in to comment.