fix(test): Wait for Vault server in watch tests #2053
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix flaky tests by polling Vault's
/v1/sys/health
endpoint. This ensures the server is ready before tests attempt to connect, preventing a race condition during Vault dev server startup.Example of a failed run: https://github.com/hashicorp/consul-template/actions/runs/14620430375/job/41018777729?pr=2052
Breakdown of the issue in
watch/watch_test.go
:main
callsnewTestVault()
to start a Vault dev server usingexec.Command("vault", "server", "-dev", ...)
and stores the command intestVault
.cmd.Start()
,main
creates Vault clients and callsvaultTokenSetup(clients)
.vaultTokenSetup
then attempts to communicate with the Vault API throughvc.Sys().EnableAuthWithOptions(...)
, which fails with the connection refused error as the process is not in listening state yet.Seems to affect the Enterprise tests more than the others.
You can simulate the test error locally by making the test launch an intermediate script which sleeps indefinitely.