-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test for parameterized summary counts
- Loading branch information
Mahmood Ali
committed
Mar 25, 2021
1 parent
15fd4f3
commit 032945b
Showing
7 changed files
with
279 additions
and
4 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