e2e: adjust flaky timings (#26771)

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:
```
This commit is contained in:
Daniel Bennett
2025-09-15 15:54:53 -04:00
committed by GitHub
parent ababacc9ab
commit f47cb5d10f
2 changed files with 40 additions and 29 deletions

View File

@@ -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),
))
}

View File

@@ -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 {