From f47cb5d10f126083717b5866fae0ba89cd970497 Mon Sep 17 00:00:00 2001 From: Daniel Bennett Date: Mon, 15 Sep 2025 15:54:53 -0400 Subject: [PATCH] e2e: adjust flaky timings (#26771) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit hopefully fixes: ``` TestOversubscription/testExec: oversubscription_test.go:57: submitting job: "./input/exec.hcl" oversubscription_test.go:72: oversubscription_test.go:72: expected condition to pass within wait context ↪ error: wait: timeout exceeded: expect '31457280' in stdout, got: 'stat {...}/cat.stdout.0: no such file or directory' ``` and in separate runs, ``` TestTaskAPI/testTaskAPI_Auth: taskapi_test.go:85: taskapi_test.go:85: expected string to have suffix ↪ suffix: Unauthorized ↪ string: ``` ``` TestTaskAPI/testTaskAPI_Auth: taskapi_test.go:85: taskapi_test.go:85: expected string to have suffix ↪ suffix: Forbidden ↪ string: ``` --- e2e/oversubscription/oversubscription_test.go | 5 +- e2e/workload_id/input/api-auth.nomad.hcl | 64 +++++++++++-------- 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/e2e/oversubscription/oversubscription_test.go b/e2e/oversubscription/oversubscription_test.go index e0a5db54d..436c96bf6 100644 --- a/e2e/oversubscription/oversubscription_test.go +++ b/e2e/oversubscription/oversubscription_test.go @@ -68,10 +68,11 @@ func testExec(t *testing.T) { return nil } - // wait for poststart to run, up to 20 seconds + // wait for poststart to run, up to 60 seconds. + // this accounts for variability in exec task start time. must.Wait(t, wait.InitialSuccess( wait.ErrorFunc(testFunc), - wait.Timeout(time.Second*20), + wait.Timeout(time.Second*60), wait.Gap(time.Second*2), )) } diff --git a/e2e/workload_id/input/api-auth.nomad.hcl b/e2e/workload_id/input/api-auth.nomad.hcl index 4e684eca8..0347ea097 100644 --- a/e2e/workload_id/input/api-auth.nomad.hcl +++ b/e2e/workload_id/input/api-auth.nomad.hcl @@ -1,6 +1,32 @@ # Copyright (c) HashiCorp, Inc. # SPDX-License-Identifier: BUSL-1.1 +locals { + # these include a sleep, so docker logs can consistently be retrieved + no_token_401 = <<-SCRIPT + curl -v \ + --unix-socket ${NOMAD_SECRETS_DIR}/api.sock \ + localhost/v1/agent/health + sleep 1 + SCRIPT + + bad_token_403 = <<-SCRIPT + curl -v \ + --unix-socket ${NOMAD_SECRETS_DIR}/api.sock \ + --header "X-Nomad-Token: 37297754-3b87-41da-9ac7-d98fd934deed" \ + localhost/v1/agent/health + sleep 1 + SCRIPT + + good_token = <<-SCRIPT + curl -v \ + --unix-socket ${NOMAD_SECRETS_DIR}/api.sock \ + --header "X-Nomad-Token: ${NOMAD_TOKEN}" \ + localhost/v1/agent/health + sleep 1 + SCRIPT +} + job "api-auth" { type = "batch" @@ -15,12 +41,9 @@ job "api-auth" { task "none" { driver = "docker" config { - image = "curlimages/curl:7.87.0" - args = [ - "--unix-socket", "${NOMAD_SECRETS_DIR}/api.sock", - "-v", - "localhost/v1/agent/health", - ] + image = "curlimages/curl:7.87.0" + command = "sh" + args = ["-c", "${local.no_token_401}"] } resources { cpu = 16 @@ -33,13 +56,9 @@ job "api-auth" { task "bad" { driver = "docker" config { - image = "curlimages/curl:7.87.0" - args = [ - "--unix-socket", "${NOMAD_SECRETS_DIR}/api.sock", - "-H", "X-Nomad-Token: 37297754-3b87-41da-9ac7-d98fd934deed", - "-v", - "localhost/v1/agent/health", - ] + image = "curlimages/curl:7.87.0" + command = "sh" + args = ["-c", "${local.bad_token_403}"] } resources { cpu = 16 @@ -53,13 +72,9 @@ job "api-auth" { driver = "docker" config { - image = "curlimages/curl:7.87.0" - args = [ - "--unix-socket", "${NOMAD_SECRETS_DIR}/api.sock", - "-H", "Authorization: Bearer ${NOMAD_TOKEN}", - "-v", - "localhost/v1/agent/health", - ] + image = "curlimages/curl:7.87.0" + command = "sh" + args = ["-c", "${local.good_token}"] } identity { @@ -78,13 +93,8 @@ job "api-auth" { driver = "exec" config { - command = "curl" - args = [ - "-H", "Authorization: Bearer ${NOMAD_TOKEN}", - "--unix-socket", "${NOMAD_SECRETS_DIR}/api.sock", - "-v", - "localhost/v1/agent/health", - ] + command = "sh" + args = ["-c", "${local.good_token}"] } identity {