onsi / ginkgo

A Modern Testing Framework for Go
http://onsi.github.io/ginkgo/
MIT License
8.37k stars 660 forks source link

explain cause of context cancelation #1326

Open pohly opened 10 months ago

pohly commented 10 months ago

The default "context canceled" is often not useful in a Ginkgo E2E suite. Was the context canceled because of some local, test-specific timeout? Was it explicitly canceled? Did the overall suite time out? What the heck are the timeouts in this particular job that is failing?

This can be addressed via context.WithCancelCause: whenever Ginkgo creates a context (whether it's for a timeout or cancelation), use context.WithCancelCause and provide a cause that contains the information that answers the questions above.

pohly commented 10 months ago

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 https://github.com/kubernetes/kubernetes/pull/122481 is some code that I wrote for this, feel free to copy whatever you find useful.

onsi commented 10 months ago

arlight this is on master now