e2e util split new alloc and await placement, new WaitForDeployment
This commit is contained in:
parent
f23f9fd99e
commit
d73606e54e
|
@ -54,15 +54,13 @@ func WaitForNodesReady(t *testing.T, nomadClient *api.Client, nodes int) {
|
|||
})
|
||||
}
|
||||
|
||||
func RegisterAndWaitForAllocs(t *testing.T, nomadClient *api.Client, jobFile string, jobID string) []*api.AllocationListStub {
|
||||
func RegisterAllocs(t *testing.T, nomadClient *api.Client, jobFile string, jobID string) []*api.AllocationListStub {
|
||||
// Parse job
|
||||
job, err := jobspec.ParseFile(jobFile)
|
||||
require := require.New(t)
|
||||
require.Nil(err)
|
||||
job.ID = helper.StringToPtr(jobID)
|
||||
|
||||
g := NewGomegaWithT(t)
|
||||
|
||||
// Register job
|
||||
jobs := nomadClient.Jobs()
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
|
@ -75,15 +73,26 @@ func RegisterAndWaitForAllocs(t *testing.T, nomadClient *api.Client, jobFile str
|
|||
require.NoError(err)
|
||||
})
|
||||
|
||||
allocs, _, _ := jobs.Allocations(jobID, false, nil)
|
||||
return allocs
|
||||
}
|
||||
|
||||
func RegisterAndWaitForAllocs(t *testing.T, nomadClient *api.Client, jobFile string, jobID string) []*api.AllocationListStub {
|
||||
// Parse job
|
||||
require := require.New(t)
|
||||
allocs := RegisterAllocs(t, nomadClient, jobFile, jobID)
|
||||
g := NewGomegaWithT(t)
|
||||
jobs := nomadClient.Jobs()
|
||||
|
||||
// Wrap in retry to wait until placement
|
||||
g.Eventually(func() []*api.AllocationListStub {
|
||||
// Look for allocations
|
||||
allocs, _, _ := jobs.Allocations(*job.ID, false, nil)
|
||||
allocs, _, _ := jobs.Allocations(jobID, false, nil)
|
||||
return allocs
|
||||
}, 30*time.Second, time.Second).ShouldNot(BeEmpty())
|
||||
|
||||
allocs, _, err := jobs.Allocations(*job.ID, false, nil)
|
||||
require.Nil(err)
|
||||
allocs, _, err := jobs.Allocations(jobID, false, nil)
|
||||
require.NoError(err)
|
||||
return allocs
|
||||
}
|
||||
|
||||
|
@ -100,3 +109,21 @@ func WaitForAllocRunning(t *testing.T, nomadClient *api.Client, allocID string)
|
|||
t.Fatalf("failed to wait on alloc: %v", err)
|
||||
})
|
||||
}
|
||||
|
||||
func WaitForDeployment(t *testing.T, nomadClient *api.Client, deployID string, status string, statusDesc string) {
|
||||
testutil.WaitForResultRetries(retries, func() (bool, error) {
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
deploy, _, err := nomadClient.Deployments().Info(deployID, nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if deploy.Status == status && deploy.StatusDescription == statusDesc {
|
||||
return true, nil
|
||||
}
|
||||
return false, fmt.Errorf("expected status %s \"%s\", but got: %s \"%s\"", deploy.Status, deploy.StatusDescription)
|
||||
|
||||
}, func(err error) {
|
||||
t.Fatalf("failed to wait on alloc: %v", err)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue