Skip to content

Refactor testcontext APIs#10782

Open
stephanos wants to merge 2 commits into
mainfrom
stephanos/testcontext-api-cleanup
Open

Refactor testcontext APIs#10782
stephanos wants to merge 2 commits into
mainfrom
stephanos/testcontext-api-cleanup

Conversation

@stephanos

@stephanos stephanos commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

What changed?

Adds testcontext.For, testcontext.AttachDecorator, and testcontext.DefaultTimeout.

Why?

This is a refactor to prepare for #10417 which adds adaptive context extension for Await.

No behavior change expected.


var (
_ Env = (*TestEnv)(nil)
defaultTestTimeout = 90 * time.Second * debug.TimeoutMultiplier

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.

moved to testcontext package; consolidated there

Comment thread tests/testcore/context.go
return ctx
}

// setupTestTimeoutWithContext creates a context that will be canceled on timeout,

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.

moved into test_env.go

@stephanos stephanos force-pushed the stephanos/testcontext-api-cleanup branch from 64d6db8 to 54db92d Compare June 19, 2026 21:57
Comment thread tests/testcore/context.go
"go.temporal.io/server/common/testing/testcontext"
)

type versionHeadersContextKey struct{}

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.

moved to test_env.go

@stephanos stephanos force-pushed the stephanos/testcontext-api-cleanup branch 2 times, most recently from 5b91a45 to a80ec1f Compare June 19, 2026 22:02
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) {

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.

drive-by improvement


// 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 {

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 was awkward as it had to be used together with New.

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 {

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.

New wasn't quite right as this doesn't create one if it already exists.

@stephanos stephanos changed the title Prepare test context API cleanup Refactor testcontext APIs Jun 19, 2026
@stephanos stephanos marked this pull request as ready for review June 19, 2026 22:09
@stephanos stephanos requested review from a team as code owners June 19, 2026 22:09
@stephanos stephanos force-pushed the stephanos/testcontext-api-cleanup branch from f4eba11 to 84e35e3 Compare June 19, 2026 22:10
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