Class WorkflowEnvironment
- Namespace
- Temporalio.Testing
- Assembly
- Temporalio.dll
Workflow environment for testing with Temporal.
public class WorkflowEnvironment : IAsyncDisposable
- Inheritance
-
WorkflowEnvironment
- Implements
- Inherited Members
Remarks
This class is NOT thread safe and not safe for use by concurrent tests. Time skipping is locked/unlocked at an environment level, so while reuse is supported, independent concurrent use can have side effects.
In modern versions of .NET, this implements IAsyncDisposable which means it can be
used in an await using block.
Constructors
WorkflowEnvironment(ITemporalClient)
Initializes a new instance of the WorkflowEnvironment class for the given client that does not support time skipping.
public WorkflowEnvironment(ITemporalClient client)
Parameters
clientITemporalClientClient to use for this environment.
Properties
Client
Gets the client for this workflow environment.
public ITemporalClient Client { get; protected init; }
Property Value
Logger
Gets a logger for this environment.
protected ILogger<WorkflowEnvironment> Logger { get; }
Property Value
SupportsTimeSkipping
Gets a value indicating whether this environment supports time skipping.
public virtual bool SupportsTimeSkipping { get; }
Property Value
Methods
CreateNexusEndpointAsync(string, string)
Create Nexus endpoint on this test environment.
public Task<Endpoint> CreateNexusEndpointAsync(string name, string taskQueue)
Parameters
Returns
Remarks
WARNING: Nexus support is experimental.
DelayAsync(int, CancellationToken?)
Sleep in this environment.
public Task DelayAsync(int millisecondsDelay, CancellationToken? cancellationToken = null)
Parameters
millisecondsDelayintNumber of milliseconds to sleep.
cancellationTokenCancellationToken?If present, cancellation token for the sleep.
Returns
- Task
Completion task.
Remarks
In non-time-skipping environments, this is just Delay(int, CancellationToken), but in time-skipping environments this may simply fast forward time.
DelayAsync(TimeSpan, CancellationToken?)
Sleep in this environment.
public virtual Task DelayAsync(TimeSpan delay, CancellationToken? cancellationToken = null)
Parameters
delayTimeSpanAmount of time to sleep.
cancellationTokenCancellationToken?If present, cancellation token for the sleep.
Returns
- Task
Completion task.
Remarks
In non-time-skipping environments, this is just Delay(TimeSpan, CancellationToken), but in time-skipping environments this may simply fast forward time.
DeleteNexusEndpointAsync(Endpoint)
Delete Nexus endpoint on this test environment.
public Task DeleteNexusEndpointAsync(Endpoint endpoint)
Parameters
endpointEndpointEndpoint.
Returns
- Task
Task for completion.
Remarks
WARNING: Nexus support is experimental.
DisposeAsync()
Shutdown and dispose this server.
public ValueTask DisposeAsync()
Returns
- ValueTask
Completion task.
GetCurrentTimeAsync()
Get the current time for the environment.
public virtual Task<DateTime> GetCurrentTimeAsync()
Returns
Remarks
For non-time-skipping environments this is just Now, but in time-skipping environments this may be a different time.
ShutdownAsync()
Shutdown this server.
public virtual Task ShutdownAsync()
Returns
- Task
Completion task.
Remarks
This has no effect for workflow environments constructed with a simple client.
StartLocalAsync(WorkflowEnvironmentStartLocalOptions?)
Start a local test server with full Temporal capabilities but no time skipping.
public static Task<WorkflowEnvironment> StartLocalAsync(WorkflowEnvironmentStartLocalOptions? options = null)
Parameters
optionsWorkflowEnvironmentStartLocalOptionsOptions for the server.
Returns
- Task<WorkflowEnvironment>
The started environment.
Remarks
By default this lazily downloads a server from the internet if not already present.
StartTimeSkippingAsync(WorkflowEnvironmentStartTimeSkippingOptions?)
Start a local test server with time skipping but limited Temporal capabilities.
public static Task<WorkflowEnvironment> StartTimeSkippingAsync(WorkflowEnvironmentStartTimeSkippingOptions? options = null)
Parameters
optionsWorkflowEnvironmentStartTimeSkippingOptionsOptions for the server.
Returns
- Task<WorkflowEnvironment>
The started environment.
Remarks
By default this lazily downloads a server from the internet if not already present.
WithAutoTimeSkippingDisabled(Action)
Run a function with automatic time skipping disabled.
public void WithAutoTimeSkippingDisabled(Action func)
Parameters
funcActionFunction to run.
Remarks
This has no effect if time skipping is already disabled (which is always the case in non-time-skipping environments), so the function just runs.
WithAutoTimeSkippingDisabledAsync(Func<Task>)
Run a function with automatic time skipping disabled.
public Task WithAutoTimeSkippingDisabledAsync(Func<Task> func)
Parameters
Returns
- Task
Task for completion.
Remarks
This has no effect if time skipping is already disabled (which is always the case in non-time-skipping environments), so the function just runs.
WithAutoTimeSkippingDisabledAsync<T>(Func<Task<T>>)
Run a function with automatic time skipping disabled.
public virtual Task<T> WithAutoTimeSkippingDisabledAsync<T>(Func<Task<T>> func)
Parameters
Returns
- Task<T>
Task with resulting value.
Type Parameters
TType of result.
Remarks
This has no effect if time skipping is already disabled (which is always the case in non-time-skipping environments), so the function just runs.
WithAutoTimeSkippingDisabled<T>(Func<T>)
Run a function with automatic time skipping disabled.
public T WithAutoTimeSkippingDisabled<T>(Func<T> func)
Parameters
funcFunc<T>Function to run.
Returns
- T
Resulting value.
Type Parameters
TType of result.
Remarks
This has no effect if time skipping is already disabled (which is always the case in non-time-skipping environments), so the function just runs.