-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10145 from hashicorp/b-periodic-init-status
periodic: always reset periodic children status
- Loading branch information
Showing
10 changed files
with
318 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
job "periodic" { | ||
datacenters = ["dc1"] | ||
type = "batch" | ||
|
||
constraint { | ||
attribute = "${attr.kernel.name}" | ||
operator = "set_contains_any" | ||
value = "darwin,linux" | ||
} | ||
|
||
parameterized { | ||
meta_optional = ["i"] | ||
} | ||
|
||
group "group" { | ||
task "task" { | ||
driver = "docker" | ||
|
||
config { | ||
image = "busybox:1" | ||
command = "/bin/sh" | ||
args = ["-c", "sleep 5"] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package parameterized | ||
|
||
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 ParameterizedTest struct { | ||
framework.TC | ||
jobIDs []string | ||
} | ||
|
||
func init() { | ||
framework.AddSuites(&framework.TestSuite{ | ||
Component: "Parameterized", | ||
CanRunLocal: true, | ||
Cases: []framework.TestCase{ | ||
new(ParameterizedTest), | ||
}, | ||
}) | ||
} | ||
|
||
func (tc *ParameterizedTest) BeforeAll(f *framework.F) { | ||
e2eutil.WaitForLeader(f.T(), tc.Nomad()) | ||
} | ||
|
||
func (tc *ParameterizedTest) 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 *ParameterizedTest) TestParameterizedDispatch_Basic(f *framework.F) { | ||
t := f.T() | ||
|
||
uuid := uuid.Generate() | ||
jobID := fmt.Sprintf("dispatch-%s", uuid[0:8]) | ||
tc.jobIDs = append(tc.jobIDs, jobID) | ||
|
||
// register job | ||
require.NoError(t, e2eutil.Register(jobID, "parameterized/input/simple.nomad")) | ||
|
||
// force dispatch | ||
dispatched := 4 | ||
|
||
for i := 0; i < dispatched; i++ { | ||
require.NoError(t, e2eutil.Dispatch(jobID, map[string]string{"i": fmt.Sprintf("%v", i)}, "")) | ||
} | ||
|
||
testutil.WaitForResult(func() (bool, error) { | ||
children, err := e2eutil.DispatchedJobs(jobID) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
dead := 0 | ||
for _, c := range children { | ||
if c["Status"] != "dead" { | ||
return false, fmt.Errorf("expected periodic job to be dead") | ||
} | ||
dead++ | ||
} | ||
|
||
if dead != dispatched { | ||
return false, fmt.Errorf("expected %d but found %d children", dispatched, dead) | ||
} | ||
|
||
return true, nil | ||
}, func(err error) { | ||
require.NoError(t, err) | ||
}) | ||
|
||
// Assert there are no pending children | ||
summary, err := e2eutil.ChildrenJobSummary(jobID) | ||
require.NoError(t, err) | ||
require.Len(t, summary, 1) | ||
require.Equal(t, summary[0]["Pending"], "0") | ||
require.Equal(t, summary[0]["Running"], "0") | ||
require.Equal(t, summary[0]["Dead"], fmt.Sprintf("%v", dispatched)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.