Documentation
¶
Overview ¶
Package durabletasktest runs orchestrations, activities, and entities in process for tests.
A Host starts an in-memory Durable Task service, a worker for the orchestrators, activities, and entities in a task.TaskRegistry, and a client connected to the same service. Communication uses an in-memory gRPC transport, so no network ports or external services are required.
registry := task.NewTaskRegistry()
registry.AddOrchestratorN("Greeting", greeting)
registry.AddActivityN("SayHello", sayHello)
host := durabletasktest.New(t, registry)
id, err := host.Client().ScheduleNewOrchestration(ctx, "Greeting")
...
metadata, err := host.Client().WaitForOrchestrationCompletion(ctx, id)
Orchestrations run through the same worker, executor, and client code paths that production workers use. To isolate an orchestrator from external dependencies, register stub activities in the test's registry.
Timers use the Go runtime clock. Tests can use testing/synctest to advance timers without waiting in real time. Failed orchestrations can be rewound with the same history-safety limitations as the production worker. Rewind enqueues recovery and preserves successful work; outstanding timers and activities are recovered. Activities can run again if their results are unavailable. Purged children without retained results are recreated without their previous history; conflicting child IDs prevent rewind. Histories without a committed execution start cannot be rewound. Durable entities are supported, including entity critical sections: signals and calls to a locked entity from outside its critical section wait until the lock is released. An entity operation is dispatched in a work item with the entity's state, so an operation's input and the entity's state must fit together in a 4 MiB work item. SignalEntity returns an error wrapping api.ErrInvalidArgument if a signal doesn't fit with the entity's current state. Calls that don't fit when they are dispatched fail; signals are dropped, and the host logs a warning, which New also reports with testing.TB.Log. An entity batch whose result exceeds 4 MiB isn't applied, and its calls fail with the non-retriable error type EntityResultTooLarge. Entity query pages contain at most 100 entries and 64 MiB of serialized data; follow the continuation token to retrieve the remaining entities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Host ¶
type Host struct {
// contains filtered or unexported fields
}
Host is an in-process Durable Task service with a running worker and a client.
func New ¶
New starts a Host for a test and closes it when the test and its subtests finish. It stops the test with testing.TB.Fatal if the host can't start. The host also reports entity signals that the service drops with testing.TB.Log.
func NewHost ¶
NewHost starts an in-memory service and a worker for the registry. Call Host.Close to stop it. ctx bounds startup only.
func (*Host) Client ¶
func (h *Host) Client() *client.TaskHubGrpcClient
Client returns a client connected to the host's in-memory service.
type Option ¶
type Option func(*options)
Option configures a Host.
func WithClientOptions ¶
func WithClientOptions(opts ...client.TaskHubGrpcClientOption) Option
WithClientOptions adds options for the host's client, such as a data converter.
func WithLogger ¶
WithLogger sets the logger used by the worker, client, and in-memory service. The service logs a warning when it drops an entity signal. By default, the host discards log output.
func WithWorkerOptions ¶
func WithWorkerOptions(opts ...client.TaskHubGrpcWorkerOption) Option
WithWorkerOptions adds options for the host's worker, such as a data converter or versioning settings.