Make affinity e2e tests wait for leader through Before method
This commit is contained in:
parent
24788e9ab7
commit
9890ac7583
|
@ -28,6 +28,11 @@ func init() {
|
|||
})
|
||||
}
|
||||
|
||||
func (tc *BasicAffinityTest) BeforeAll(f *framework.F) {
|
||||
// Ensure cluster has leader before running tests
|
||||
framework.WaitForLeader(f.T(), tc.Nomad())
|
||||
}
|
||||
|
||||
func (tc *BasicAffinityTest) registerAndWaitForAllocs(f *framework.F, jobFile string, prefix string) []*api.AllocationListStub {
|
||||
nomadClient := tc.Nomad()
|
||||
// Parse job
|
||||
|
|
21
e2e/framework/utils.go
Normal file
21
e2e/framework/utils.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package framework
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/nomad/api"
|
||||
"github.com/hashicorp/nomad/testutil"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// retries is used to control how many times to retry checking if the cluster has a leader yet
|
||||
const retries = 500
|
||||
|
||||
func WaitForLeader(t *testing.T, nomadClient *api.Client) {
|
||||
statusAPI := nomadClient.Status()
|
||||
|
||||
testutil.WaitForResultRetries(retries, func() (bool, error) {
|
||||
leader, err := statusAPI.Leader()
|
||||
return leader != "", err
|
||||
}, func(err error) {
|
||||
t.Fatalf("failed to find leader: %v", err)
|
||||
})
|
||||
}
|
Loading…
Reference in a new issue