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

improve context support #716

Open
pohly opened this issue Jan 4, 2024 · 2 comments
Open

improve context support #716

pohly opened this issue Jan 4, 2024 · 2 comments

Comments

@pohly
Copy link

pohly commented Jan 4, 2024

When a context is canceled, context.Cause may be able to provide a better explanation that just "context canceled" (the error returned by Context.Err). This can be useful to figure out which timeout triggered, in particular when Ginkgo also supports it (onsi/ginkgo#1326).

fail("Context was cancelled")
could check for a cause and include that explanation. Bonus points for avoiding "Context was cancelled because context canceled" 😁

When a Gomega async assertion has its own timeout and the callback function accepts a context, create a context that contains that timeout and pass that to the callback. Right now, the context given to gomega.Eventually is passed through (

inValues = append(inValues, reflect.ValueOf(assertion.ctx))
), so if the callback blocks, it doesn't time out as requested via a per-assertion timeout.

@pohly
Copy link
Author

pohly commented Jan 4, 2024

It is a bit annoying that Go doesn't properly support "cause" in all variants of the context.With* calls. As it stands now (Go 1.21), one has to re-implement context.WithTimeout to get a cause both when the timeout occurs and for early cancelation.

test/utils/ktesting/contexthelper.go from kubernetes/kubernetes#122481 is some code that I wrote for this, feel free to copy whatever you find useful.

@onsi
Copy link
Owner

onsi commented Jan 17, 2024

hey there - the latest code on master now supports emiting the context cancellation reason. i started working on the second bit (passing in a context myself) but quickly ran into complexity so i'm bailing out in the interest of getting the context cancellation reason done.

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

No branches or pull requests

2 participants