Skip to content

experimental: faster tfversion tests #493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

experimental: faster tfversion tests #493

wants to merge 4 commits into from

Conversation

bbasata
Copy link
Contributor

@bbasata bbasata commented Apr 24, 2025

For fun, not to be merged.

The tfversion tests are fairly unique in that they specify "TF_ACC_TERRAFORM_VERSION". As a consequence, each of these tests downloads Terraform into its own temporary directory. This PR asks: what if they shared one temporary directory?

  • Find Terraform binaries that we've already downloaded instead of repeatedly downloading them
  • Read a TF_LOG_INSTALLER environment variable to log hc-install activity. Works best with a branch of hc-install that prepends log levels to logged messages.
  • What if ... provider installation can also be de-duplicated?

Before:

$ time go test ./tfversion -count=1
ok  	github.com/hashicorp/terraform-plugin-testing/tfversion	223.588s
go test ./tfversion -count=1  45.66s user 29.61s system 33% cpu 3:44.32 total

After:

$ time go test ./tfversion -count=1
ok  	github.com/hashicorp/terraform-plugin-testing/tfversion	58.465s
go test ./tfversion -count=1  22.14s user 12.61s system 58% cpu 58.982 total

bbasata added 3 commits April 22, 2025 15:33
* Find Terraform binaries that we've already downloaded instead of
  repeatedly downloading them
* Read a TF_LOG_INSTALLER environment variable to log hc-install
  activity. Works best with a branch of hc-install that prepends log
  levels to logged messages.
* What if? Could provider installation be optimized?

Before:
```
$ time go test ./tfversion -count=1
ok  	github.com/hashicorp/terraform-plugin-testing/tfversion	223.588s
go test ./tfversion -count=1  45.66s user 29.61s system 33% cpu 3:44.32 total
```

After:
```
$ time go test ./tfversion -count=1
ok  	github.com/hashicorp/terraform-plugin-testing/tfversion	58.465s
go test ./tfversion -count=1  22.14s user 12.61s system 58% cpu 58.982 total
```
@bbasata bbasata requested a review from a team as a code owner April 24, 2025 22:19
@bbasata bbasata closed this Apr 24, 2025
@bbasata bbasata reopened this Apr 24, 2025
InstallDir: tfDir,
Product: product.Terraform,
Version: tfVersion,
})
}
sources = append(sources, findSource, releasesSource)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the part that makes this faster. Instead of a "releases source," use a "find source" and a "releases source."

strings.TrimRight(tempDir, string(os.PathSeparator)),
"plugintest-terraform",
strconv.Itoa(os.Getpid()),
tfVersion.String(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One directory per-version, per-process.

ok  	github.com/hashicorp/terraform-plugin-testing/tfversion	16.360s
TF_LOG_INSTALLER=info go test -v ./tfversion  25.66s user 14.50s system 236% cpu 16.969 total
Base automatically changed from tidy to main April 29, 2025 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant