Problem
WhenAnyTask is a core public API exported via whenAny() from @microsoft/durabletask-js. It is used in orchestrations to wait for the first of multiple concurrent tasks to complete. Despite being a critical component of the task system, it has zero unit tests.
Its sibling WhenAllTask has 7 comprehensive tests in when-all-task.spec.ts, covering edge cases like empty arrays, pre-completed children, fail-fast behavior, and parent notification. WhenAnyTask has none.
File: packages/durabletask-js/src/task/when-any-task.ts
Root Cause
The WhenAnyTask class was implemented without corresponding test coverage. As the task system grew and WhenAllTask received thorough tests (including a regression fix for issue #131), WhenAnyTask was not given equivalent treatment.
Proposed Fix
Add a comprehensive unit test file (when-any-task.spec.ts) covering:
- Empty input validation (constructor throws)
- Basic completion on first child
- Result semantics (returns the completed child Task itself, not its result)
- Child failure behavior (WhenAny does not propagate failure — returns failed task as result)
- Idempotent completion guard (subsequent child completions are ignored)
- Pre-completed children (immediate completion during construction)
- Pre-failed children
- Multiple pre-completed children (first in iteration order wins)
- Single-child edge case
- Parent composite task notification chain
- No completion when no children have completed
Impact
Severity: Medium — no runtime bug, but any future refactoring of WhenAnyTask or CompositeTask has no test safety net. The absence of tests also means the subtle behavior differences from WhenAllTask (e.g., WhenAny does NOT propagate child failures to itself) are undocumented in test form.
Problem
WhenAnyTaskis a core public API exported viawhenAny()from@microsoft/durabletask-js. It is used in orchestrations to wait for the first of multiple concurrent tasks to complete. Despite being a critical component of the task system, it has zero unit tests.Its sibling
WhenAllTaskhas 7 comprehensive tests inwhen-all-task.spec.ts, covering edge cases like empty arrays, pre-completed children, fail-fast behavior, and parent notification.WhenAnyTaskhas none.File:
packages/durabletask-js/src/task/when-any-task.tsRoot Cause
The
WhenAnyTaskclass was implemented without corresponding test coverage. As the task system grew andWhenAllTaskreceived thorough tests (including a regression fix for issue #131),WhenAnyTaskwas not given equivalent treatment.Proposed Fix
Add a comprehensive unit test file (
when-any-task.spec.ts) covering:Impact
Severity: Medium — no runtime bug, but any future refactoring of
WhenAnyTaskorCompositeTaskhas no test safety net. The absence of tests also means the subtle behavior differences fromWhenAllTask(e.g., WhenAny does NOT propagate child failures to itself) are undocumented in test form.