Skip to content
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

Skip sleep in VCR replaying mode #12785

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wyardley
Copy link
Contributor

@wyardley wyardley commented Jan 16, 2025

In SleepInSecondsForTest(), skip the sleep when VCR_MODE is REPLAYING. This makes the assumption that the sleep is always related to a condition that's already mitigated by the fact that we're using prerecorded fixtures, but it could be extended later to override this behavior if necessary.

Fixes hashicorp/terraform-provider-google#20916

Replaying mode with change:

--- PASS: TestAccResourceGoogleProjectDefaultServiceAccountsDisable (24.32s)
PASS
ok  	github.com/hashicorp/terraform-provider-google/google/services/resourcemanager	25.464s

without change (this one has a 5s sleep, so the difference is small, but you can see it more dramatically on something with a longer sleep)

--- PASS: TestAccResourceGoogleProjectDefaultServiceAccountsDisable (29.51s)
PASS
ok  	github.com/hashicorp/terraform-provider-google/google/services/resourcemanager	30.720s

Release Note Template for Downstream PRs (will be copied)

See Write release notes for guidance.


Copy link

Hello! I am a robot. Tests will require approval from a repository maintainer to run.

@c2thorn, a repository maintainer, has been assigned to review your changes. If you have not received review feedback within 2 business days, please leave a comment on this PR asking them to take a look.

You can help make sure that review is quick by doing a self-review and by running impacted tests locally.

In `SleepInSecondsForTest()`, skip the sleep when `VCR_MODE` is
`REPLAYING`. This makes the assumption that the sleep is always related
to a condition that's already mitigated by the fact that we're using
prerecorded fixtures, but it could be extended later to override this
behavior if necessary.

Fixes hashicorp/terraform-provider-google#20916
@@ -90,7 +91,10 @@ func SkipIfVcr(t *testing.T) {

func SleepInSecondsForTest(t int) resource.TestCheckFunc {
return func(s *terraform.State) error {
time.Sleep(time.Duration(t) * time.Second)
// Assume we never want to sleep when we're in replaying mode.
if os.Getenv("VCR_MODE") != "REPLAYING" {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tested this both with / without assignment, but gut is that this is probably good enough? it already seems to work fine / not error if the env var is not defined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-approval Pull requests that need reviewer's approval to run presubmit tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sleep statement in tests with VCR enabled
2 participants