Skip to content

Commit

Permalink
make the test helper a little nicer
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross committed Nov 16, 2023
1 parent cb81f51 commit 0d3defb
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions e2e/rescheduling/rescheduling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@ import (

const ns = "default"

func reschedulingTestCleanup(t *testing.T, jobID string) func() {
return func() {
t.Helper()

func cleanupJob(t *testing.T, jobID string) {
t.Helper()
t.Cleanup(func() {
if os.Getenv("NOMAD_TEST_SKIPCLEANUP") == "1" {
return
}

e2eutil.StopJob(jobID, "-purge", "-detach")
_, err := e2eutil.Command("nomad", "system", "gc")
test.NoError(t, err)
}
})
}

// Note: most of the StopJob calls in this test suite will return an
Expand All @@ -46,7 +45,7 @@ func TestRescheduling_Service_NoReschedule(t *testing.T) {
jobID := "test-no-reschedule-" + uuid.Generate()[0:8]
must.NoError(t, e2eutil.Register(jobID, "./input/norescheduling_service.nomad"))

t.Cleanup(reschedulingTestCleanup(t, jobID))
cleanupJob(t, jobID)

expected := []string{"failed", "failed", "failed"}
must.NoError(t,
Expand All @@ -61,7 +60,7 @@ func TestRescheduling_System_NoReschedule(t *testing.T) {
jobID := "test-no-reschedule-" + uuid.Generate()[0:8]
must.NoError(t, e2eutil.Register(jobID, "./input/norescheduling_system.nomad"))

t.Cleanup(reschedulingTestCleanup(t, jobID))
cleanupJob(t, jobID)

must.NoError(t,
e2eutil.WaitForAllocStatusComparison(
Expand All @@ -84,7 +83,7 @@ func TestRescheduling_Default(t *testing.T) {
jobID := "test-default-reschedule-" + uuid.Generate()[0:8]
must.NoError(t, e2eutil.Register(jobID, "./input/rescheduling_default.nomad"))

t.Cleanup(reschedulingTestCleanup(t, jobID))
cleanupJob(t, jobID)

expected := []string{"failed", "failed", "failed"}
must.NoError(t,
Expand All @@ -107,7 +106,7 @@ func TestRescheduling_MaxAttempts(t *testing.T) {
jobID := "test-reschedule-fail-" + uuid.Generate()[0:8]
must.NoError(t, e2eutil.Register(jobID, "./input/rescheduling_fail.nomad"))

t.Cleanup(reschedulingTestCleanup(t, jobID))
cleanupJob(t, jobID)

expected := []string{"failed", "failed", "failed"}
must.NoError(t,
Expand Down Expand Up @@ -146,7 +145,7 @@ func TestRescheduling_Success(t *testing.T) {
jobID := "test-reschedule-success-" + uuid.Generate()[0:8]
must.NoError(t, e2eutil.Register(jobID, "./input/rescheduling_success.nomad"))

t.Cleanup(reschedulingTestCleanup(t, jobID))
cleanupJob(t, jobID)

must.Wait(t, wait.InitialSuccess(
wait.BoolFunc(func() bool {
Expand All @@ -172,7 +171,7 @@ func TestRescheduling_WithUpdate(t *testing.T) {
jobID := "test-reschedule-update-" + uuid.Generate()[0:8]
must.NoError(t, e2eutil.Register(jobID, "./input/rescheduling_update.nomad"))

t.Cleanup(reschedulingTestCleanup(t, jobID))
cleanupJob(t, jobID)

expected := []string{"running", "running", "running"}
must.NoError(t,
Expand Down Expand Up @@ -206,7 +205,7 @@ func TestRescheduling_WithCanary(t *testing.T) {
jobID := "test-reschedule-canary-" + uuid.Generate()[0:8]
must.NoError(t, e2eutil.Register(jobID, "./input/rescheduling_canary.nomad"))

t.Cleanup(reschedulingTestCleanup(t, jobID))
cleanupJob(t, jobID)

expected := []string{"running", "running", "running"}
must.NoError(t,
Expand Down Expand Up @@ -248,7 +247,7 @@ func TestRescheduling_WithCanaryAutoRevert(t *testing.T) {
jobID := "test-reschedule-canary-revert-" + uuid.Generate()[0:8]
must.NoError(t, e2eutil.Register(jobID, "./input/rescheduling_canary_autorevert.nomad"))

t.Cleanup(reschedulingTestCleanup(t, jobID))
cleanupJob(t, jobID)

expected := []string{"running", "running", "running"}
must.NoError(t,
Expand Down Expand Up @@ -296,7 +295,7 @@ func TestRescheduling_MaxParallel(t *testing.T) {
jobID := "test-reschedule-maxp-" + uuid.Generate()[0:8]
must.NoError(t, e2eutil.Register(jobID, "./input/rescheduling_maxp.nomad"))

t.Cleanup(reschedulingTestCleanup(t, jobID))
cleanupJob(t, jobID)

expected := []string{"running", "running", "running"}
must.NoError(t,
Expand Down Expand Up @@ -343,7 +342,7 @@ func TestRescheduling_MaxParallelAutoRevert(t *testing.T) {
jobID := "test-reschedule-maxp-revert-" + uuid.Generate()[0:8]
must.NoError(t, e2eutil.Register(jobID, "./input/rescheduling_maxp_autorevert.nomad"))

t.Cleanup(reschedulingTestCleanup(t, jobID))
cleanupJob(t, jobID)

expected := []string{"running", "running", "running"}
must.NoError(t,
Expand Down Expand Up @@ -419,7 +418,7 @@ func TestRescheduling_ProgressDeadline(t *testing.T) {
jobID := "test-reschedule-deadline-" + uuid.Generate()[0:8]
must.NoError(t, e2eutil.Register(jobID, "./input/rescheduling_progressdeadline.nomad"))

t.Cleanup(reschedulingTestCleanup(t, jobID))
cleanupJob(t, jobID)

expected := []string{"running"}
must.NoError(t,
Expand Down Expand Up @@ -450,7 +449,7 @@ func TestRescheduling_ProgressDeadlineFail(t *testing.T) {
jobID := "test-reschedule-deadline-fail" + uuid.Generate()[0:8]
must.NoError(t, e2eutil.Register(jobID, "./input/rescheduling_progressdeadline_fail.nomad"))

t.Cleanup(reschedulingTestCleanup(t, jobID))
cleanupJob(t, jobID)

testutil.WaitForResult(func() (bool, error) {
_, err := e2eutil.LastDeploymentID(jobID, ns)
Expand Down

0 comments on commit 0d3defb

Please sign in to comment.