Refactor testcontext APIs#10782
Open
stephanos wants to merge 2 commits into
Open
Conversation
stephanos
commented
Jun 19, 2026
|
|
||
| var ( | ||
| _ Env = (*TestEnv)(nil) | ||
| defaultTestTimeout = 90 * time.Second * debug.TimeoutMultiplier |
Contributor
Author
There was a problem hiding this comment.
moved to testcontext package; consolidated there
stephanos
commented
Jun 19, 2026
| return ctx | ||
| } | ||
|
|
||
| // setupTestTimeoutWithContext creates a context that will be canceled on timeout, |
Contributor
Author
There was a problem hiding this comment.
moved into test_env.go
64d6db8 to
54db92d
Compare
stephanos
commented
Jun 19, 2026
| "go.temporal.io/server/common/testing/testcontext" | ||
| ) | ||
|
|
||
| type versionHeadersContextKey struct{} |
Contributor
Author
There was a problem hiding this comment.
moved to test_env.go
5b91a45 to
a80ec1f
Compare
stephanos
commented
Jun 19, 2026
| deadline, ok := ctx.Deadline() | ||
| require.True(t, ok) | ||
| require.WithinDuration(t, time.Now().Add(10*time.Second), deadline, 50*time.Millisecond) | ||
| synctest.Test(t, func(t *testing.T) { |
Contributor
Author
There was a problem hiding this comment.
drive-by improvement
stephanos
commented
Jun 19, 2026
|
|
||
| // WithContextDecorator applies decorator to the test-scoped context once for key. | ||
| // Reusing the same key is a no-op. | ||
| func WithContextDecorator[K comparable](key K, decorator func(context.Context) context.Context) Option { |
Contributor
Author
There was a problem hiding this comment.
This was awkward as it had to be used together with New.
stephanos
commented
Jun 19, 2026
| func New(tb testing.TB, opts ...Option) context.Context { | ||
| // return the same context, but an explicit different timeout fails instead of | ||
| // being silently ignored. | ||
| func For(tb testing.TB, opts ...Option) context.Context { |
Contributor
Author
There was a problem hiding this comment.
New wasn't quite right as this doesn't create one if it already exists.
f4eba11 to
84e35e3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed?
Adds
testcontext.For,testcontext.AttachDecorator, andtestcontext.DefaultTimeout.Why?
This is a refactor to prepare for #10417 which adds adaptive context extension for
Await.No behavior change expected.