Make affinity e2e tests wait for leader through Before method

This commit is contained in:
Preetha Appan 2018-12-19 09:56:44 -06:00
parent 24788e9ab7
commit 9890ac7583
No known key found for this signature in database
GPG key ID: 9F7C19990A50EAFC
2 changed files with 26 additions and 0 deletions

View file

@ -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
View 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)
})
}