From 6c3928553854eed01a7741f4c3838db3c1df6c78 Mon Sep 17 00:00:00 2001 From: James Rasell Date: Mon, 7 Apr 2025 15:15:29 +0200 Subject: [PATCH] e2e: Ensure test resources are cleaned. (#25611) I couldn't find any reason the exec2 HTTP jobs were not being run with a generated cleanup function, so I added this. The deletion of the DHV ACL policy does not seem like it would have any negative impact. --- .../dynamic_host_volumes_test.go | 6 ++++++ e2e/exec2/exec2_test.go | 12 ++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/e2e/dynamic_host_volumes/dynamic_host_volumes_test.go b/e2e/dynamic_host_volumes/dynamic_host_volumes_test.go index 3ec8f9c4f..191de22b5 100644 --- a/e2e/dynamic_host_volumes/dynamic_host_volumes_test.go +++ b/e2e/dynamic_host_volumes/dynamic_host_volumes_test.go @@ -14,6 +14,7 @@ import ( "github.com/hashicorp/nomad/e2e/e2eutil" "github.com/hashicorp/nomad/e2e/v3/jobs3" "github.com/hashicorp/nomad/e2e/v3/volumes3" + "github.com/shoenig/test" "github.com/shoenig/test/must" "github.com/shoenig/test/wait" ) @@ -60,6 +61,11 @@ func TestDynamicHostVolumes_RegisterWorkflow(t *testing.T) { must.NoError(t, err) t.Logf("[%v] ACL policy for job %q created", time.Since(start), submitted.JobID()) + t.Cleanup(func() { + _, err := nomad.ACLPolicies().Delete("register-volumes-policy", nil) + test.NoError(t, err) + }) + must.NoError(t, e2eutil.Dispatch(submitted.JobID(), map[string]string{ "vol_name": "registered-volume", diff --git a/e2e/exec2/exec2_test.go b/e2e/exec2/exec2_test.go index 67cb3ab58..e0ac7b6b6 100644 --- a/e2e/exec2/exec2_test.go +++ b/e2e/exec2/exec2_test.go @@ -81,15 +81,11 @@ func testCountdash(t *testing.T) { } func testHTTP(t *testing.T) { - job, _ := jobs3.Submit(t, - "./input/http.hcl", - jobs3.DisableCleanup(), - ) + job, httpCleanup := jobs3.Submit(t, "./input/http.hcl") + t.Cleanup(httpCleanup) - job2, _ := jobs3.Submit(t, - "./input/http_curl.hcl", - jobs3.DisableCleanup(), - ) + job2, httpCurlCleanup := jobs3.Submit(t, "./input/http_curl.hcl") + t.Cleanup(httpCurlCleanup) logs := job.TaskLogs("backend", "http") must.StrContains(t, logs.Stderr, `"GET / HTTP/1.1" 200 -`) // healthcheck