Skip to content

test(enterprise): run the Terraform workspace tag tests in parallel - #33018

Merged
kylecarbs merged 1 commit into
mainfrom
parallel-terraform-tags-test
Dec 6, 2026
Merged

kylecarbs merged 1 commit into
mainfrom
parallel-terraform-tags-test

Conversation

@kylecarbs

@kylecarbs kylecarbs commented Dec 6, 2026 •

Copy link
Copy Markdown
Member

TestWorkspaceTagsTerraform ran its 20 real Terraform builds one after another. It set TF_CLI_CONFIG_FILE with t.Setenv, and a test that calls t.Setenv cannot run in parallel.

coderdenttest.NewExternalProvisionerDaemonTerraform now takes the Terraform CLI config path and sets terraform.ServeOptions.CliConfigPath, which the provisioner already passes to Terraform. TestWorkspaceTagsTerraform, its subtests, and TestWorkspaceTemplateParamsChange (which used the same t.Setenv) pass the path that way and call t.Parallel().

enterprise/coderd test binary, main at 9023596 against this branch (12 cores, local Postgres 17, -tags=testsmallbatch -test.parallel=8, two runs each, 1,229 tests passed in every run):

main This PR
Wall time 121.4 s, 121.9 s 58.7 s, 56.6 s
Total CPU (Go, Terraform, Postgres) 365 s, 359 s 412 s, 392 s
Peak RSS of the test binary 3.8 GB, 3.9 GB 4.2 GB, 4.1 GB

Total CPU goes up by about 10% because up to eight Terraform builds now run at once and each one takes longer than it did alone (about 7 s against 3.5 s). The package used 3 of 12 cores before and uses 7 now.

CI on this PR passed on Linux, macOS, Windows, and with -race. Windows has no provider cache, so there each build downloads the provider from the registry, now several at a time. I did not measure the gain on CI runners: enterprise/coderd took 69.5 s in this PR's Linux job against 212.5 s in the last full run (#33011), but this run served most other packages from the test cache, so the two are not comparable.

Decision log

Why a parameter. NewExternalProvisionerDaemonTerraform has three callers. A required parameter makes each one state its choice; the scale test passes "" and keeps Terraform's default config. An options struct seemed too much for one field.

The config still takes effect. With HTTPS_PROXY pointed at a closed port, so that the registry is unreachable, TestWorkspaceTemplateParamsChange and TestWorkspaceTagsTerraform/{tag_param,no_tags} pass on this branch. A plain terraform init of the same provider block fails under that proxy setting. So the builds use the provider mirror named in the config file.

Isolation between parallel builds. Each provisioner daemon already has its own CachePath and work directory (t.TempDir()), so parallel builds do not share a plugin cache. They only read the provider mirror. The CLI config file lives in the persistent cache directory, not in a test's temporary directory, so it is still there when the parallel subtests run after the parent function returns.

Flake check. The two tests passed 6 times in a row at -test.parallel=8 and twice at -test.parallel=16 (32 results per run).

Checks run locally. golangci-lint on ./enterprise/coderd/... and ./enterprise/scaletest/prebuilds/..., paralleltestctx on ./enterprise/..., make lint/go/new-code lint/emdash, and the full enterprise/coderd package four times. enterprise/scaletest/prebuilds was compiled and vetted, not run.

This PR was generated by Coder Agents on behalf of @kylecarbs.

TestWorkspaceTagsTerraform ran its 20 real Terraform builds one after
another, because it set TF_CLI_CONFIG_FILE with t.Setenv, and a test
that calls t.Setenv cannot run in parallel. It took about 70 of the
package's 120 seconds.

NewExternalProvisionerDaemonTerraform now takes the Terraform CLI
config path and gives it to the provisioner, which already passes it to
Terraform. TestWorkspaceTagsTerraform, its subtests, and
TestWorkspaceTemplateParamsChange use that and call t.Parallel.
@kylecarbs
kylecarbs marked this pull request as ready for review December 6, 2026 08:13
@kylecarbs
kylecarbs merged commit 61179e5 into main Dec 6, 2026
62 checks passed
@kylecarbs
kylecarbs deleted the parallel-terraform-tags-test branch December 6, 2026 08:13
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 6, 2026

This branch had an error being deployed

1 failed deployment
docs-preview — 2fb19a7b Deployed Dec 6, 2026 by kylecarbs via cleanup #721
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants