Skip to content

Adaptive test timeouts via Await#10417

Draft
stephanos wants to merge 3 commits into
mainfrom
stephanos/testcontext-extend
Draft

Adaptive test timeouts via Await#10417
stephanos wants to merge 3 commits into
mainfrom
stephanos/testcontext-extend

Conversation

@stephanos

@stephanos stephanos commented May 28, 2026

Copy link
Copy Markdown
Contributor

What changed?

Adds testcontext.EnsureRemaining and has await use it so long await calls can request additional test-scoped context time while still respecting the test context cap.

Why?

Await calls can need more time than the default test context has left (esp after the environment setup). Extending the test timeout in this way allows for (1) stuck tests to fail earlier than the default test timeout and (2) legitimately longer running tests to pass without manually tweaking the test timeout.

@stephanos stephanos force-pushed the stephanos/await-attempt-timeout branch 3 times, most recently from 360f0fb to 8b8a010 Compare May 28, 2026 22:31
@stephanos stephanos force-pushed the stephanos/testcontext-extend branch 2 times, most recently from 2cffae6 to 5fb966d Compare May 28, 2026 22:41
@stephanos stephanos force-pushed the stephanos/await-attempt-timeout branch from 8b8a010 to 2985a57 Compare May 28, 2026 22:41
@stephanos stephanos force-pushed the stephanos/testcontext-extend branch from 5fb966d to d311c81 Compare May 28, 2026 22:55
@stephanos stephanos force-pushed the stephanos/await-attempt-timeout branch 2 times, most recently from 1076781 to fa6a741 Compare May 28, 2026 22:57
@stephanos stephanos force-pushed the stephanos/testcontext-extend branch from d311c81 to e49a9ee Compare May 28, 2026 23:02
@stephanos stephanos force-pushed the stephanos/await-attempt-timeout branch from fa6a741 to be3a125 Compare May 28, 2026 23:02
@stephanos stephanos force-pushed the stephanos/testcontext-extend branch from e49a9ee to 66e861b Compare May 28, 2026 23:06
@stephanos stephanos force-pushed the stephanos/await-attempt-timeout branch 2 times, most recently from 0543253 to ee36c2f Compare May 28, 2026 23:07
@stephanos stephanos force-pushed the stephanos/testcontext-extend branch from 66e861b to 58edaea Compare May 28, 2026 23:10
@stephanos stephanos force-pushed the stephanos/await-attempt-timeout branch 3 times, most recently from 944d4e4 to c46c348 Compare May 28, 2026 23:19
@stephanos stephanos force-pushed the stephanos/testcontext-extend branch from 58edaea to 0484cd8 Compare May 28, 2026 23:19
@stephanos stephanos force-pushed the stephanos/await-attempt-timeout branch from c46c348 to 7c54cb7 Compare May 28, 2026 23:35
@stephanos stephanos force-pushed the stephanos/testcontext-extend branch 2 times, most recently from d899349 to 5e71cbc Compare May 28, 2026 23:42
@stephanos stephanos force-pushed the stephanos/await-attempt-timeout branch 2 times, most recently from 3af47cb to 530f40c Compare May 28, 2026 23:47
@stephanos stephanos force-pushed the stephanos/testcontext-extend branch from 5e71cbc to 3639e99 Compare May 28, 2026 23:47
@stephanos stephanos force-pushed the stephanos/await-attempt-timeout branch 3 times, most recently from 719c74f to 996f88b Compare May 29, 2026 00:03
@stephanos stephanos force-pushed the stephanos/testcontext-extend branch 2 times, most recently from 0bfea95 to b44d21a Compare May 29, 2026 00:09
@stephanos stephanos force-pushed the stephanos/testcontext-extend branch 8 times, most recently from e8df25d to 95dae66 Compare June 11, 2026 05:46
@@ -1,71 +0,0 @@
package await

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Integrated these into require_ctx_test.go instead; that's better as they are more end-to-end

// may add decorators, but an explicit different timeout fails instead of being
// silently ignored.
func New(tb testing.TB, opts ...Option) context.Context {
func For(tb testing.TB, opts ...Option) context.Context {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed to For as New wasn't quite accurate

@stephanos stephanos force-pushed the stephanos/testcontext-extend branch from 95dae66 to d28b928 Compare June 11, 2026 05:50
Comment thread tests/testcore/test_env.go Outdated
@stephanos stephanos force-pushed the stephanos/testcontext-extend branch from d28b928 to b097f2a Compare June 11, 2026 05:52
Comment thread tests/testcore/context.go Outdated
@stephanos stephanos force-pushed the stephanos/testcontext-extend branch 3 times, most recently from 8368d92 to 83cc415 Compare June 11, 2026 06:04
// AttachDecorator applies decorator to the test-scoped context once for key.
// Reusing the same key is a no-op. If the test context does not exist yet,
// AttachDecorator creates it with the default timeout.
func AttachDecorator[K comparable](tb testing.TB, key K, decorator func(context.Context) context.Context) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This seems better than going through For to me now

@stephanos stephanos force-pushed the stephanos/testcontext-extend branch 5 times, most recently from 1a06d15 to d8ee116 Compare June 16, 2026 18:06
@stephanos stephanos force-pushed the stephanos/testcontext-extend branch from d8ee116 to 087fb8a Compare June 19, 2026 21:42
@stephanos stephanos force-pushed the stephanos/testcontext-extend branch from 087fb8a to 8bd4ba6 Compare June 19, 2026 21:52
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

Successfully merging this pull request may close these issues.

1 participant