2021-01-22 14:18:17 +00:00
|
|
|
package periodic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/e2e/e2eutil"
|
|
|
|
"github.com/hashicorp/nomad/e2e/framework"
|
|
|
|
"github.com/hashicorp/nomad/helper/uuid"
|
|
|
|
"github.com/hashicorp/nomad/testutil"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
type PeriodicTest struct {
|
|
|
|
framework.TC
|
|
|
|
jobIDs []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
framework.AddSuites(&framework.TestSuite{
|
|
|
|
Component: "Periodic",
|
|
|
|
CanRunLocal: true,
|
|
|
|
Cases: []framework.TestCase{
|
|
|
|
new(PeriodicTest),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tc *PeriodicTest) BeforeAll(f *framework.F) {
|
|
|
|
e2eutil.WaitForLeader(f.T(), tc.Nomad())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tc *PeriodicTest) AfterEach(f *framework.F) {
|
|
|
|
nomadClient := tc.Nomad()
|
|
|
|
j := nomadClient.Jobs()
|
|
|
|
|
|
|
|
for _, id := range tc.jobIDs {
|
|
|
|
j.Deregister(id, true, nil)
|
|
|
|
}
|
|
|
|
_, err := e2eutil.Command("nomad", "system", "gc")
|
|
|
|
f.NoError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tc *PeriodicTest) TestPeriodicDispatch_Basic(f *framework.F) {
|
|
|
|
t := f.T()
|
|
|
|
|
|
|
|
uuid := uuid.Generate()
|
|
|
|
jobID := fmt.Sprintf("periodicjob-%s", uuid[0:8])
|
|
|
|
tc.jobIDs = append(tc.jobIDs, jobID)
|
|
|
|
|
|
|
|
// register job
|
2021-02-11 10:08:48 +00:00
|
|
|
require.NoError(t, e2eutil.Register(jobID, "periodic/input/simple.nomad"))
|
2021-01-22 14:18:17 +00:00
|
|
|
|
|
|
|
// force dispatch
|
|
|
|
require.NoError(t, e2eutil.PeriodicForce(jobID))
|
|
|
|
|
2021-02-11 10:08:48 +00:00
|
|
|
testutil.WaitForResult(func() (bool, error) {
|
2021-02-18 17:21:53 +00:00
|
|
|
children, err := e2eutil.PreviouslyLaunched(jobID)
|
2021-02-11 10:08:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
2021-01-22 14:18:17 +00:00
|
|
|
|
2021-02-18 17:21:53 +00:00
|
|
|
for _, c := range children {
|
|
|
|
if c["Status"] == "dead" {
|
|
|
|
return true, nil
|
|
|
|
}
|
2021-01-22 14:18:17 +00:00
|
|
|
}
|
2021-02-18 17:21:53 +00:00
|
|
|
return false, fmt.Errorf("expected periodic job to be dead")
|
2021-01-22 14:18:17 +00:00
|
|
|
}, func(err error) {
|
|
|
|
require.NoError(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
// Assert there are no pending children
|
2021-02-18 17:21:53 +00:00
|
|
|
summary, err := e2eutil.ChildrenJobSummary(jobID)
|
2021-01-22 14:18:17 +00:00
|
|
|
require.NoError(t, err)
|
2021-02-18 17:21:53 +00:00
|
|
|
require.Len(t, summary, 1)
|
|
|
|
require.Equal(t, summary[0]["Pending"], "0")
|
|
|
|
require.Equal(t, summary[0]["Dead"], "1")
|
2021-01-22 14:18:17 +00:00
|
|
|
}
|