Class MillraceTestHost
An in-memory Millrace host that runs work deterministically, for testing applications built on it (ARCHITECTURE.md §8).
public sealed class MillraceTestHost : IAsyncDisposable
- Inheritance
-
MillraceTestHost
- Implements
- Inherited Members
Remarks
The worker pool and scheduler are switched off. Instead, RunUntilIdleAsync(bool, CancellationToken) drains the queue on the calling thread: activate what is due, claim it, run it, apply the transition, repeat until nothing is left. So a test reads
await host.Jobs.EnqueueAsync<IEmailSender>(s => s.SendAsync(orderId));
await host.RunUntilIdleAsync();
Assert.True(sent);
rather than polling with sleeps and hoping. Time is a Microsoft.Extensions.Time.Testing.FakeTimeProvider, so delays, retry backoff and signal timeouts are reached with AdvanceTime(TimeSpan) instead of waiting — a seven-day timeout is one call, not seven days.
Storage is the bundled in-memory provider, which is explicitly not durable. This is for testing your jobs and workflows; the storage contract itself is covered by the conformance kit.
Properties
- Jobs
The enqueue API, as the application under test sees it.
- Services
Services registered on the host, for resolving your own types.
- Time
The controllable clock. Prefer AdvanceTime(TimeSpan) for moving it.
- Workflows
The workflow API, as the application under test sees it.
Methods
- AdvanceTime(TimeSpan)
Moves the clock forward and activates anything that became due.
- Create(Action<IServiceCollection>?, Action<MillraceBuilder>?, DateTimeOffset?)
Builds a host, registering the application's own services and any workflows.
- DisposeAsync()
Tears down the host and everything it built.
- GetDataAsync<TData>(WorkflowInstanceId, CancellationToken)
The workflow instance's data document.
- GetInstanceAsync(WorkflowInstanceId, CancellationToken)
The stored workflow instance, or null.
- GetInstanceStateAsync(WorkflowInstanceId, CancellationToken)
The workflow instance's current state.
- GetJobAsync(JobId, CancellationToken)
The stored job, or null if there is no such job.
- RunUntilIdleAsync(bool, CancellationToken)
Runs every claimable job to completion, including work that running them enqueues.