mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
The E2E test for periodic dispatch jobs has a `cron` trigger for once a minute. If the test happens to run at the top of the minute, it's possible for the forced dispatch to run from the test code, then the periodic timer triggers and leaves a running child job. This fails the test because it expects only a single job in the "dead" state. Make it so that the `cron` expression is implausible to run during our test window, and migrate the test off the old framework while we're at it.
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package periodic
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/hashicorp/nomad/e2e/e2eutil"
|
|
"github.com/hashicorp/nomad/e2e/v3/jobs3"
|
|
"github.com/shoenig/test/must"
|
|
"github.com/shoenig/test/wait"
|
|
)
|
|
|
|
func TestPeriodicDispatch_Basic(t *testing.T) {
|
|
|
|
sub, cleanup := jobs3.Submit(t, "input/simple.nomad", jobs3.Dispatcher())
|
|
t.Cleanup(cleanup)
|
|
|
|
// force dispatch and wait for the dispatched job to finish
|
|
must.NoError(t, e2eutil.PeriodicForce(sub.JobID()))
|
|
must.Wait(t, wait.InitialSuccess(
|
|
wait.ErrorFunc(func() error {
|
|
children, err := e2eutil.PreviouslyLaunched(sub.JobID())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, c := range children {
|
|
if c["Status"] == "dead" {
|
|
return nil
|
|
}
|
|
}
|
|
return fmt.Errorf("expected periodic job to be dead")
|
|
|
|
}),
|
|
wait.Timeout(30*time.Second),
|
|
wait.Gap(time.Second),
|
|
))
|
|
|
|
// Assert there are no pending children
|
|
summary, err := e2eutil.ChildrenJobSummary(sub.JobID())
|
|
must.NoError(t, err)
|
|
must.Len(t, 1, summary)
|
|
must.Eq(t, "0", summary[0]["Pending"])
|
|
must.Eq(t, "0", summary[0]["Running"])
|
|
must.Eq(t, "1", summary[0]["Dead"])
|
|
}
|