Skip to content

Add withWorkerAndClient convenience to TemporalTestServer#144

Open
RalucaP wants to merge 2 commits into
apple:mainfrom
RalucaP:rppc/add-worker-and-client-test-helper
Open

Add withWorkerAndClient convenience to TemporalTestServer#144
RalucaP wants to merge 2 commits into
apple:mainfrom
RalucaP:rppc/add-worker-and-client-test-helper

Conversation

@RalucaP

@RalucaP RalucaP commented May 6, 2026

Copy link
Copy Markdown
Contributor

Closes #143.

Motivation

Integration tests require nesting withConnectedWorker and withConnectedClient plus creating a TemporalWorker.Configuration by hand every time.

Modifications

  • Add withWorkerAndClient on TemporalTestServer that creates a worker config with a unique task queue, starts the worker, connects a client, and passes (taskQueue, client) to the closure.
  • Update the testing documentation to use the new helper, simplifying the integration and time-skipping examples.

Result

The common integration test setup is a single call. Testing docs are 34 lines shorter as a result.

Test Plan

Added a test covering workflow execution through the helper. Updated the testing docs and verified the new examples are correct.

@RalucaP RalucaP mentioned this pull request May 6, 2026
@RalucaP RalucaP force-pushed the rppc/add-worker-and-client-test-helper branch from 6ddcd5e to 028b802 Compare May 7, 2026 11:23
activities: [any ActivityDefinition] = [],
workflows: [any WorkflowDefinition.Type] = [],
namespace: String = "default",
interceptors: [any WorkerInterceptor] = [],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
interceptors: [any WorkerInterceptor] = [],
workerInterceptors: [any WorkerInterceptor] = [],

logger.logLevel = .info
return logger
}(),
_ body: sending @escaping @isolated(any) (String, TemporalClient) async throws -> sending Result

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can this closure actually be nonisolated(nonseding) instead of sending @escaping @isolated(any)?

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.

Updated, thanks!

@RalucaP RalucaP force-pushed the rppc/add-worker-and-client-test-helper branch from 028b802 to ea2d688 Compare May 15, 2026 17:47
RalucaP added 2 commits May 15, 2026 19:49
Combines withConnectedWorker and withConnectedClient into a single call
that handles worker configuration and task queue generation internally.
Replaces the manual withConnectedWorker + withConnectedClient nesting in
the integration and time-skipping examples with the new helper.
@RalucaP RalucaP force-pushed the rppc/add-worker-and-client-test-helper branch from ea2d688 to 6be93eb Compare May 15, 2026 17:53
@RalucaP RalucaP requested a review from FranzBusch May 15, 2026 17:55
logger.logLevel = .info
return logger
}(),
_ body: nonisolated(nonsending) (String, TemporalClient) async throws -> sending Result

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nonisolated(nonsending) is enabled by default in this repo. Also we don't need the Result type to be sending.

Suggested change
_ body: nonisolated(nonsending) (String, TemporalClient) async throws -> sending Result
body: (String, TemporalClient) async throws -> Result

/// - body: An async closure that receives the task queue name and a connected client.
/// - Returns: The value returned by `body`.
/// - Throws: Any error thrown while creating the worker, connecting the client, or by the `body` closure.
public func withWorkerAndClient<Result: Sendable>(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
public func withWorkerAndClient<Result: Sendable>(
public func withWorkerAndClient<Result>(

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.

Add a combined worker-and-client test helper to TemporalTestServer

2 participants