Skip to content

v2: Context-aware WaitFor#2957

Merged
pierreprinetti merged 1 commit intogophercloud:masterfrom
sardinasystems:context-aware-waitfor
Mar 18, 2024
Merged

v2: Context-aware WaitFor#2957
pierreprinetti merged 1 commit intogophercloud:masterfrom
sardinasystems:context-aware-waitfor

Conversation

@vooon
Copy link
Copy Markdown
Contributor

@vooon vooon commented Feb 29, 2024

Fixes #2956

@github-actions github-actions bot added semver:major Breaking change and removed semver:major Breaking change labels Feb 29, 2024
@pierreprinetti
Copy link
Copy Markdown
Member

pierreprinetti commented Feb 29, 2024

Good catch, thanks.

I would remove the argument in seconds and let the caller pass a context with a deadline. The predicate function should also accept a context, so that we delegate to the caller the cancellation of hanging functions. The function could be the just called “wait”. WDYT?

@vooon
Copy link
Copy Markdown
Contributor Author

vooon commented Feb 29, 2024

@pierreprinetti indeed in many cases context with the deadline is enough, but i found it handy option to pass a timeout.

Context of the predicate anyway should be canceled once we exit WaitFor, so it's just handy way of use either WithCancel or WithTimeout if timeout > 0.

I'm unsure about other WaitFor* funcs, unfortunately my regex-fu is not that great...

@github-actions github-actions bot added semver:major Breaking change and removed semver:major Breaking change labels Feb 29, 2024
@pierreprinetti
Copy link
Copy Markdown
Member

i found it handy option to pass a timeout

The context library provides a convenience function for setting a timeout. Note that if you set a deadline or timeout on a context that already has one, the shortest delay correctly wins.

@pierreprinetti
Copy link
Copy Markdown
Member

My stance here is: this is not Gophercloud's job. There are plenty of libraries out there that do Wait in fanciful ways. I understand that we might continue providing a function that covers the basic case, but we should keep complexity at a minimum to avoid bugs. Accepting a context and letting the user set it appropriately seems to me like a reasonable compromise.

@vooon
Copy link
Copy Markdown
Contributor Author

vooon commented Feb 29, 2024

@pierreprinetti agree, that surface should be minimal but enough. I also agree, that usually you just pass deadline ctx and do not expect fancy logic inside.

Optional timeout just makes tests a bit easier to write, but i often have limited context in test suite anyway.

I'll drop timeouts.

@github-actions github-actions bot added semver:major Breaking change and removed semver:major Breaking change labels Feb 29, 2024
@vooon vooon force-pushed the context-aware-waitfor branch 2 times, most recently from 99b98d9 to d1e6046 Compare February 29, 2024 16:59
@github-actions github-actions bot added semver:major Breaking change and removed semver:major Breaking change labels Feb 29, 2024
@github-actions github-actions bot added semver:major Breaking change and removed semver:major Breaking change labels Mar 11, 2024
@vooon
Copy link
Copy Markdown
Contributor Author

vooon commented Mar 11, 2024

@pierreprinetti done.

@vooon vooon force-pushed the context-aware-waitfor branch from 03ce053 to 38af2a9 Compare March 11, 2024 17:50
@github-actions github-actions bot added semver:major Breaking change and removed semver:major Breaking change labels Mar 11, 2024
@pierreprinetti
Copy link
Copy Markdown
Member

pierreprinetti commented Mar 14, 2024

@vooon we may have issues here: internal/acceptance/openstack/containerinfra/v1/nodegroups_test.go

https://github.com/gophercloud/gophercloud/actions/runs/8237438492/job/22526174282?pr=2957#step:5:969

@vooon vooon force-pushed the context-aware-waitfor branch from 38af2a9 to b41b9e0 Compare March 15, 2024 16:50
@github-actions github-actions bot removed the semver:major Breaking change label Mar 15, 2024
@vooon
Copy link
Copy Markdown
Contributor Author

vooon commented Mar 15, 2024

@pierreprinetti thanks, fixed.

Copy link
Copy Markdown
Contributor

@mandre mandre left a comment

Choose a reason for hiding this comment

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

This looks great, thanks for doing this @vooon !

I'm sorry, I have merged #2994 prior to reviewing your PR. Could you once more rebase on master and update the newly introduced function to match your changes?

@github-actions github-actions bot added semver:major Breaking change and removed semver:major Breaking change labels Mar 18, 2024
@vooon vooon force-pushed the context-aware-waitfor branch from 62212e9 to 04201d6 Compare March 18, 2024 10:11
Remove timeout logic from WaitFor, just use context, Luke!
Improve gophercloud.WaitFor not to wait first second
testing: fix error validation with errors.Is
acceptance: fix node group
acceptance: remove unused ErrTimeout
baremetal: update WaitFor signature

Fix: gophercloud#2956

Co-authored-by: Martin André <martin.andre@gmail.com>
Signed-off-by: Vladimir Ermakov <vooon341@gmail.com>
@github-actions github-actions bot removed the semver:major Breaking change label Mar 18, 2024
@vooon vooon force-pushed the context-aware-waitfor branch from 04201d6 to 7bcc341 Compare March 18, 2024 10:16
@github-actions github-actions bot added the semver:major Breaking change label Mar 18, 2024
@vooon vooon requested a review from mandre March 18, 2024 10:17
@github-actions github-actions bot added semver:major Breaking change and removed semver:major Breaking change labels Mar 18, 2024
Copy link
Copy Markdown
Contributor

@mandre mandre left a comment

Choose a reason for hiding this comment

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

Thanks so much!

@github-actions github-actions bot added semver:major Breaking change and removed semver:major Breaking change labels Mar 18, 2024
@pierreprinetti
Copy link
Copy Markdown
Member

Nice! Thank you @vooon and @mandre for the additional review. I think we can merge as soon as we get the CI's blessing

@pierreprinetti pierreprinetti merged commit 7028628 into gophercloud:master Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver:major Breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v2: Context-Aware WaitFor

4 participants