durabletasktest

package
v1.0.0-beta4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func New(tb testing.TB, registry *task.TaskRegistry, opts ...Option) *Host

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

func NewHost(ctx context.Context, registry *task.TaskRegistry, opts ...Option) (*Host, error)

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.

func (*Host) Close

func (h *Host) Close(ctx context.Context) error

Close stops the worker and the in-memory service. All orchestration state is discarded. If ctx ends before in-flight work items finish, they are canceled.

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

func WithLogger(logger api.Logger) Option

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL