feat: add ExecuteStandaloneActivity to TestWorkflowEnvironment#2337
Closed
brucearctor wants to merge 1 commit into
Closed
feat: add ExecuteStandaloneActivity to TestWorkflowEnvironment#2337brucearctor wants to merge 1 commit into
brucearctor wants to merge 1 commit into
Conversation
Add ExecuteStandaloneActivity method to TestWorkflowEnvironment that executes standalone activities through the full ClientOutboundInterceptor chain, enabling testing of interceptor-dependent features such as OpenTelemetry tracing, metrics, and header propagation. Unlike TestActivityEnvironment.ExecuteActivity (which runs the activity function directly via taskHandler.Execute), this method builds and traverses the client interceptor chain before executing the activity, matching the real Client.ExecuteActivity flow. Implementation: - testClientOutboundInterceptor: terminal interceptor replacing gRPC calls with local test execution - testClientActivityHandleImpl: implements ClientActivityHandle for the test environment - executeStandaloneActivity: builds interceptor chain from registered WorkerOptions.Interceptors and routes through it Closes temporalio#2318
97d9880 to
54ec32c
Compare
Contributor
|
Thanks for the contribution, but we've decided the issue itself is not worth the effort and not quite what we want and have closed, so closing this contribution as well |
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
Adds
ExecuteStandaloneActivitytoTestWorkflowEnvironmentthat executes standalone activities through the fullClientOutboundInterceptorchain.Closes #2318
Why
Currently,
TestActivityEnvironment.ExecuteActivity()runs activity functions directly viataskHandler.Execute(), completely bypassing theClientOutboundInterceptorchain. This prevents testing of interceptor-dependent features like OpenTelemetry tracing (#2302), metrics, and header propagation without spinning up a real server.This method fills that gap by matching the real
Client.ExecuteActivityflow through the interceptor chain while keeping execution local to the test environment.How
testClientOutboundInterceptor: a terminalClientOutboundInterceptorthat replaces gRPC calls with the existing test activity task handler executiontestClientActivityHandleImpl: implementsClientActivityHandlefor the test environmentexecuteStandaloneActivity: builds the interceptor chain from registeredWorkerOptions.Interceptors(type-assertingWorkerInterceptortoClientInterceptor) and routes execution through itThe flow is:
contextWithNewHeader(ctx)→ build interceptor chain →chain.ExecuteActivity()→ user interceptors →testClientOutboundInterceptor.ExecuteActivity()→taskHandler.Execute().Design Decisions
There were a few decision points during implementation. I went with what seemed most natural given the existing codebase patterns, but am happy to revisit any of these if the maintainers prefer a different approach:
Method lives on
TestWorkflowEnvironment(not a newTestClientEnvironment) — The issue requested it onTestWorkflowEnvironment, and it keeps the API surface minimal. If a separateTestClientEnvironmentis preferred for cleaner separation, I can refactor.Interceptor chain built per-call — Rather than caching the chain, each call to
ExecuteStandaloneActivityrebuilds it. This matches how the real client initializes its chain and avoids stale state ifSetWorkerOptionsis called between invocations. If caching is preferred for performance, that would be straightforward to add.Interceptors sourced from
WorkerOptions.Interceptors— Since the test environment usesSetWorkerOptionsto configure interceptors, I type-assert eachWorkerInterceptortoClientInterceptorwhen building the chain. This works for the common case where users pass fullInterceptorimplementations (which embed both). If a separateSetClientInterceptorsoption is preferred, I can add that.Synchronous execution with result on the handle — Activities execute synchronously (matching existing test suite behavior), so
handle.Get()returns immediately.Cancel,Terminate, andDescribereturn errors indicating they are unsupported in the test environment.Tests
Added 6 tests covering:
ExecuteActivityis called and headers are present