Skip to content

Add in-memory test host for orchestrations (durabletasktest) - #183

Open
andystaples wants to merge 11 commits into
mainfrom
andystaples-orchestration-testing-design
Open

andystaples wants to merge 11 commits into
mainfrom
andystaples-orchestration-testing-design

Conversation

@andystaples

@andystaples andystaples commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Relates to #180

Adds a durabletasktest package for running orchestrations and activities inside a test process, with no emulator, network port, or Azure resource. The design follows the in-memory testing backends in the .NET, Python, and JavaScript SDKs.

Design

  • internal/inmemory implements TaskHubSidecarService in memory: instance state, history, an orchestration/activity work queue, completion-token leases, and real-time timers.
  • durabletasktest.Host serves that backend over bufconn and runs the real TaskHubGrpcWorker (via NewTaskHubGrpcWorkerWithConnectionFactory) plus a TaskHubGrpcClient. Orchestrations therefore use the same worker, executor, and client paths as they do against DTS.
  • durabletasktest.New(t, registry) starts a host and registers its cleanup with the test. NewHost(ctx, registry) is for callers that manage the lifetime themselves.
  • Errors use the shared gRPC status/reason mapping, so clients see the usual sentinels (ErrDuplicateInstance, ErrInstanceNotFound, ErrNotCompleted, ErrInvalidState, ErrFeatureNotSupported).

Supported

Activities, sub-orchestrations, timers, external events, SendEvent, continue-as-new (including carryover events), suspend/resume, terminate (including recursive), restart, QueryInstances, ListInstanceIDs, single/batch/filter purge (including recursive), history streaming, scheduled start, ID reuse policy, and worker work-item filters. When a work-item stream closes, its leased work is re-queued.

Not included

  • Virtual time. Timers fire in real time, which matches the other SDKs' test backends.
  • Durable entities and rewind. Entity RPCs and RewindInstance return Unimplemented (ErrFeatureNotSupported). An orchestration that calls, signals, or locks an entity fails with a NotSupported failure.
  • Extended sessions and chunked completions. The worker falls back to standard completions.
  • Payloads over the 4 MiB message limit. History is streamed, and new events are split across turns. A single event that can't fit fails the instance with OrchestrationWorkItemTooLarge. Requests over 4 MiB are rejected with ResourceExhausted, as DTS does. An activity result over 4 MiB fails the task with non-retriable ActivityResponseTooLarge instead of being redelivered; Fail oversized activity and entity completions instead of abandoning and re-executing them #202 tracks the equivalent worker behavior against DTS. QueryInstances rejects TaskHubNames filters, because the host has no task hub identity.

README.md documents usage and limitations. CI coverage now includes both new packages.

Adds an in-memory TaskHubSidecarService implementation and a durabletasktest package that runs the real worker and client against it over bufconn. Durable entities, rewind, and virtual time are not supported.

Refs #180

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 20, 2026 18:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved critical defects in partial-response handling and recursive termination can corrupt orchestration replay and terminate unrelated replacement instances.

7 open issues
What changed in this PR

Adds durabletasktest, an in-process testing surface for orchestrations that uses the existing worker, executor, and client without an emulator or external service.

Changes:

  • Adds a test host with automatic cleanup and configurable worker/client options.
  • Implements an in-memory service for work dispatch, orchestration state, history, and instance management, using real-time timers.
  • Adds tests, usage documentation, and CI coverage for the new packages.
File Description
README.md Documents test-host usage, limitations, and coverage commands.
internal/​inmemory/​work.go Implements work leasing, filtering, completion, and orchestration actions.
internal/​inmemory/​work_test.go Tests continue-as-new event carryover and stale-result removal.
internal/​inmemory/​server.go Implements instance state, timers, lifecycle operations, and history streaming.
internal/​inmemory/​query.go Adds instance queries, ID pagination, and purge operations.
durabletasktest/​host.go Provides the public host over an in-memory gRPC transport.
durabletasktest/​host_test.go Exercises execution, events, timers, management, and unsupported features.
CHANGELOG.md Records the new testing package and supported capabilities.
.github/​workflows/​pr-validation.yml Includes both new packages in coverage reporting.

Review effort: Balanced

Comment thread internal/inmemory/server.go Resolved
Comment thread internal/inmemory/work.go Resolved
Comment thread durabletasktest/host.go Resolved
Comment thread durabletasktest/host.go Resolved
Comment thread internal/inmemory/query.go Resolved
Comment thread internal/inmemory/query.go Resolved
Comment thread internal/inmemory/work.go Resolved

@berndverst Bernd Verst (berndverst) left a comment

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.

Reusing the real worker and client makes this a useful test host. I would fix two cases where the host can hang otherwise-valid orchestration tests: an activity backlog can block orchestration dispatch, and a replay history over 4 MiB can stop the worker. The existing partial-turn replay and recursive-termination threads also need to be addressed before merge.

Comment thread internal/inmemory/work.go Resolved
Comment thread durabletasktest/host.go Resolved
Comment thread durabletasktest/host.go Resolved
Comment thread README.md Resolved
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 19:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The host’s gRPC and history-event limits reject supported large payloads, and suspending or resuming a scheduled orchestration can prematurely signal that it has started.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Medium severity Raise gRPC limits to support payloads over 4 MiB

durabletasktest/​host.go:126

The host's default 4 MiB gRPC receive limits reject a 5 MiB orchestration input or activity result, although DTS connections allow 64 MiB (durabletaskscheduler/options.go:27–30). Configure compatible send/receive limits on the server and every connection created by dial. Also align the individual-history-event limit at internal/inmemory/server.go:485–486 so those payloads remain replayable through history streaming.

Medium severity Preserve scheduled-start status when suspending or resuming

internal/​inmemory/​server.go:320

Suspending an instance before its scheduled start changes its status to SUSPENDED, so WaitForOrchestrationStart returns even though scheduling still blocks execution. Resuming before that time also reports RUNNING prematurely (server.go:431–433). Track actual start independently of suspension, use it for the start waiter and resume status while allowing terminal outcomes to unblock waiters, and cover scheduled-start suspend/resume in a regression test.

7 resolved since last review

Review effort: Balanced

andystaples and others added 4 commits November 23, 2026 13:38
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The module minimum is now Go 1.26, so testing/synctest is always available.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Suspending an instance before its scheduled start set its status to
SUSPENDED, so WaitForInstanceStart returned even though the scheduled
start still blocked execution, and resuming it reported RUNNING before
any turn ran. Record when the first turn commits, wait on that (or a
terminal status), and resume a never-started instance to PENDING.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
New events that together exceeded 4 MiB were sent in one work item. The
worker rejected the message as non-retryable and stopped, so the test
hung. Lease only the leading new events that fit and leave the rest for
later turns, as DTS does. If a single event can't fit, fail the instance
with a clear error instead of stopping the worker.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 21:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Recursive termination can miss newly created children, task-hub query filters are silently ignored, and stream-owned lease recovery lacks coverage for outstanding leases and completion races.

3 open issues

Review effort: Balanced

Comment thread internal/inmemory/query.go Resolved
Comment thread internal/inmemory/server.go Resolved
Comment thread internal/inmemory/work.go Resolved
andystaples and others added 5 commits November 23, 2026 16:53
The in-memory service has no task hub identity, so a query scoped to
task hub names previously ignored the filter and returned every
instance. Return Unimplemented with the FEATURE_UNSUPPORTED reason so
the client reports api.ErrFeatureNotSupported. QueryInstances is the
only RPC that accepts task hub names.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…nation

A recursive TerminateInstance that arrives while the parent's turn is
leased terminates the parent's existing children, but the in-flight
turn could still commit a new sub-orchestration that kept running after
the parent ended. When a turn creates a sub-orchestration and the parent
has a recursive termination pending or in that turn, terminate the new
child too.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Lease orchestration and activity work on one stream, close it while the
leases are outstanding, and check that a replacement stream receives the
same work with pending events in order and that the original completion
tokens are rejected with NotFound.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
A worker completion over gRPC's default 4 MiB server receive limit was
rejected at the transport. The worker then abandoned the work item and
the host dispatched it again, so the activity ran forever.

The in-memory server now accepts large messages at the transport and
enforces the DTS-equivalent 4 MiB limit itself. Oversized requests are
still rejected with ResourceExhausted, but an activity completion over
the limit fails the task with the non-retriable ActivityResponseTooLarge
error type, so the orchestration observes a TaskFailed event and the
activity isn't run again. oversizedCompletionFailure is shared so entity
completions can use the same check.

The host's client connections now mirror DTS connection defaults: a
64 MiB receive limit and no send limit. Outgoing work items and history
chunks remain within 4 MiB.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 24, 2026 00:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The termination fast path can permanently discard a pending ExecutionStarted event after abandonment, leaving history without an execution identity and causing execution-ID validation to fail.

1 open issue
3 resolved since last review

Review effort: Balanced

terminated := helpers.NewExecutionTerminatedEvent(reason, recursive)
if len(inst.history) == 0 && !inst.leased && len(inst.pending) > 0 {
// The orchestrator never ran, so complete the termination without a worker.
inst.history = append(inst.history, inst.pending[0], terminated)
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.

3 participants