testing: setting env var incompatible with parallel tests (#14405)

Neither the `os.Setenv` nor `t.Setenv` helper are safe to use in parallel tests
because environment variables are process-global. The stdlib panics if you try
to do this. Remove the `ci.Parallel()` call from all tests where we're setting
environment variables.
This commit is contained in:
Tim Gross
2022-08-30 14:49:03 -04:00
committed by GitHub
parent 36799570f6
commit 13bc6d6d8a
13 changed files with 16 additions and 54 deletions

View File

@@ -1376,14 +1376,11 @@ BAR={{key "bar"}}
// process environment variables. nomad host process environment variables
// are to be treated the same as not found environment variables.
func TestTaskTemplateManager_FiltersEnvVars(t *testing.T) {
ci.Parallel(t)
defer os.Setenv("NOMAD_TASK_NAME", os.Getenv("NOMAD_TASK_NAME"))
os.Setenv("NOMAD_TASK_NAME", "should be overridden by task")
t.Setenv("NOMAD_TASK_NAME", "should be overridden by task")
testenv := "TESTENV_" + strings.ReplaceAll(uuid.Generate(), "-", "")
os.Setenv(testenv, "MY_TEST_VALUE")
defer os.Unsetenv(testenv)
t.Setenv(testenv, "MY_TEST_VALUE")
// Make a template that will render immediately
content := `Hello Nomad Task: {{env "NOMAD_TASK_NAME"}}