improve context support
pohly opened this issue · comments
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).
gomega/internal/async_assertion.go
Line 556 in f1c8757
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 (
gomega/internal/async_assertion.go
Line 285 in f1c8757
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.
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.