Skip to content

Commit 0836424

Browse files
committed
docs: testing section
Replace the testing documentation with a language-neutral section covering the local runner, authoring a test, inspecting operations, the full API surface, workflow patterns, cloud runner, and SAM CLI. Every section now has TypeScript, Python, and Java tabs with real, verified examples from the actual testing SDK sources. Structure - Add runner.md, authoring.md, assertions.md, api-reference.md, workflow-patterns.md, cloud-runner.md, sam-cli.md. - Drop basic-tests.md, complex-workflows.md, stores.md, testing-modes.md, write-tests.md, test-operations.md, test-workflows.md, testing-tools.md, run-in-cloud.md, and the corresponding examples directories. - Reorder the nav to Runner, Authoring, Assertions, API Reference, Workflow Patterns, Cloud Runner, SAM CLI. Highlights - Document DURABLE_EXECUTION_TIME_SCALE for the Python testing SDK under Authoring / Skip time in tests, with cross-links from the Long waits workflow pattern and the API reference Control time section. - API reference reorganised by intent verbs (Create a runner, Run the handler, Drive callbacks, etc.) with explicit anchors on duplicated Cloud-side headings so in-page links resolve. - Cloud runner page regrouped so Deploy, Configure polling, and IAM permissions live under Set up the cloud runner, and each troubleshooting tip has its own heading. - Use the correct JS testing package name (@aws/durable-execution-sdk-js-testing). - Verified every method, argument, type, and return value against the TS, Python, and Java SDK and testing SDK sources. - Verified the SAM CLI commands against sam --help locally. Closes #24 Closes #25 Closes #44 Closes #45 Closes #46 Closes #47 Closes #50 Closes #62 Closes #63 Closes #64 Closes #68 Closes #80 Closes #81 Closes #82 Closes #86 Closes #133
1 parent a3568cd commit 0836424

64 files changed

Lines changed: 3648 additions & 2223 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/testing/api-reference.md

Lines changed: 1206 additions & 0 deletions
Large diffs are not rendered by default.

docs/testing/assertions.md

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# Assertions
2+
3+
After `run()` completes, the test result contains the full operation history. You can
4+
look up operations by name, filter by type, or walk the history to assert on what ran
5+
and how it ran.
6+
7+
## Assert on a step
8+
9+
Look up a step by name and check its status and result.
10+
11+
=== "TypeScript"
12+
13+
Use `runner.getOperation(name)` to get a handle to the operation, then call
14+
`getStepDetails()` to access the result.
15+
16+
```typescript
17+
--8<-- "examples/typescript/testing/assertions/assert-step.ts"
18+
```
19+
20+
=== "Python"
21+
22+
Use `result.get_step(name)` to get the `StepOperation`. The `result` attribute holds the
23+
raw serialized payload.
24+
25+
```python
26+
--8<-- "examples/python/testing/assertions/assert-step.py"
27+
```
28+
29+
=== "Java"
30+
31+
Use `result.getOperation(name)` to get the `TestOperation`, then call
32+
`getStepResult(Class<T>)` to deserialize the result.
33+
34+
```java
35+
--8<-- "examples/java/testing/assertions/assert-step.java"
36+
```
37+
38+
## Assert on a wait
39+
40+
Look up a wait operation and check that it was scheduled with the expected duration.
41+
42+
=== "TypeScript"
43+
44+
`getWaitDetails()` returns `waitSeconds` and `scheduledEndTimestamp`.
45+
46+
```typescript
47+
--8<-- "examples/typescript/testing/assertions/assert-wait.ts"
48+
```
49+
50+
=== "Python"
51+
52+
Use `result.get_wait(name)`. The `scheduled_end_timestamp` attribute is a `datetime`
53+
when the wait was scheduled to end.
54+
55+
```python
56+
--8<-- "examples/python/testing/assertions/assert-wait.py"
57+
```
58+
59+
=== "Java"
60+
61+
`getWaitDetails().scheduledEndTimestamp()` returns the scheduled end time as an
62+
`Instant`.
63+
64+
```java
65+
--8<-- "examples/java/testing/assertions/assert-wait.java"
66+
```
67+
68+
## Assert on a callback
69+
70+
For callbacks, the test drives the execution to the point where the callback is waiting,
71+
then completes it from the test.
72+
73+
=== "TypeScript"
74+
75+
Use `waitForData(WaitingOperationStatus.SUBMITTED)` to wait until the callback submitter
76+
has run, then call `sendCallbackSuccess()` to complete it.
77+
78+
```typescript
79+
--8<-- "examples/typescript/testing/assertions/assert-callback.ts"
80+
```
81+
82+
=== "Python"
83+
84+
Use `run_async()` to start the execution, `wait_for_callback()` to get the callback ID,
85+
`send_callback_success()` to complete it, then `wait_for_result()` to get the final
86+
result. All calls must happen inside the `with runner:` block.
87+
88+
```python
89+
--8<-- "examples/python/testing/assertions/assert-callback.py"
90+
```
91+
92+
=== "Java"
93+
94+
Use `run()` to reach the PENDING state, `getCallbackId()` to get the callback ID,
95+
`completeCallback()` to complete it, then `run()` again to finish the execution.
96+
97+
```java
98+
--8<-- "examples/java/testing/assertions/assert-callback.java"
99+
```
100+
101+
## Assert on a child context
102+
103+
Child contexts appear as `CONTEXT` operations in the result. You can walk their child
104+
operations to assert on what ran inside the context.
105+
106+
=== "TypeScript"
107+
108+
```typescript
109+
--8<-- "examples/typescript/testing/assertions/assert-child-context.ts"
110+
```
111+
112+
=== "Python"
113+
114+
```python
115+
--8<-- "examples/python/testing/assertions/assert-child-context.py"
116+
```
117+
118+
=== "Java"
119+
120+
```java
121+
--8<-- "examples/java/testing/assertions/assert-child-context.java"
122+
```
123+
124+
## Filter operations by status
125+
126+
When a step retries, the operation history contains one entry per attempt. Filter by
127+
status to count failures and successes separately.
128+
129+
=== "TypeScript"
130+
131+
Pass `{ status: OperationStatus.FAILED }` to `result.getOperations()` to filter.
132+
133+
```typescript
134+
--8<-- "examples/typescript/testing/assertions/filter-by-status.ts"
135+
```
136+
137+
=== "Python"
138+
139+
Use `result.get_all_operations()` to get a flat list including nested operations, then
140+
filter by `op.status`.
141+
142+
```python
143+
--8<-- "examples/python/testing/assertions/filter-by-status.py"
144+
```
145+
146+
=== "Java"
147+
148+
`result.getFailedOperations()` and `result.getSucceededOperations()` return pre-filtered
149+
lists.
150+
151+
```java
152+
--8<-- "examples/java/testing/assertions/filter-by-status.java"
153+
```
154+
155+
## See also
156+
157+
- [Authoring](authoring.md) Set up the test runner and write your first test.
158+
- [Cloud Runner](cloud-runner.md) Run tests against a deployed Lambda function.
159+
- [Step](../sdk-reference/operations/step.md)
160+
- [Wait](../sdk-reference/operations/wait.md)

docs/testing/authoring.md

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# Authoring
2+
3+
## Install the testing SDK
4+
5+
=== "TypeScript"
6+
7+
```bash
8+
npm install --save-dev @aws/durable-execution-sdk-js-testing
9+
```
10+
11+
=== "Python"
12+
13+
```bash
14+
pip install aws-durable-execution-sdk-python-testing
15+
```
16+
17+
=== "Java"
18+
19+
Add the testing dependency to your build file with `test` scope:
20+
21+
```xml
22+
<dependency>
23+
<groupId>software.amazon.lambda</groupId>
24+
<artifactId>aws-durable-execution-sdk-java-testing</artifactId>
25+
<scope>test</scope>
26+
</dependency>
27+
```
28+
29+
## Write a minimal test
30+
31+
Create a runner with your handler, call `run()`, and assert on the result.
32+
33+
=== "TypeScript"
34+
35+
Call `setupTestEnvironment()` in `beforeAll` and `teardownTestEnvironment()` in
36+
`afterAll`. Create a new runner instance in `beforeEach` so each test starts with a
37+
clean state.
38+
39+
```typescript
40+
--8<-- "examples/typescript/testing/authoring/minimal-test.ts"
41+
```
42+
43+
=== "Python"
44+
45+
Use `DurableFunctionTestRunner` as a context manager. The context manager starts the
46+
scheduler thread on entry and stops it on exit.
47+
48+
```python
49+
--8<-- "examples/python/testing/authoring/minimal-test.py"
50+
```
51+
52+
=== "Java"
53+
54+
Use `LocalDurableTestRunner.create()` with the input type and a handler function. Call
55+
`runUntilComplete()` to drive the full replay loop until the execution completes or
56+
fails.
57+
58+
```java
59+
--8<-- "examples/java/testing/authoring/minimal-test.java"
60+
```
61+
62+
## Test a failed execution
63+
64+
When your handler throws outside a step, or a step exhausts all retries, the execution
65+
fails. Assert on the status and inspect the error.
66+
67+
=== "TypeScript"
68+
69+
```typescript
70+
--8<-- "examples/typescript/testing/authoring/test-failure.ts"
71+
```
72+
73+
=== "Python"
74+
75+
```python
76+
--8<-- "examples/python/testing/authoring/test-failure.py"
77+
```
78+
79+
=== "Java"
80+
81+
```java
82+
--8<-- "examples/java/testing/authoring/test-failure.java"
83+
```
84+
85+
## Test retries
86+
87+
The test runner drives the full retry loop via replay. Configure a retry strategy on the
88+
step, and the runner re-invokes the handler as many times as needed.
89+
90+
=== "TypeScript"
91+
92+
```typescript
93+
--8<-- "examples/typescript/testing/authoring/test-retries.ts"
94+
```
95+
96+
=== "Python"
97+
98+
```python
99+
--8<-- "examples/python/testing/authoring/test-retries.py"
100+
```
101+
102+
=== "Java"
103+
104+
```java
105+
--8<-- "examples/java/testing/authoring/test-retries.java"
106+
```
107+
108+
## Skip time in tests
109+
110+
Retry backoffs and `context.wait()` durations use real time in production. The test
111+
runner collapses these delays so tests finish in milliseconds.
112+
113+
=== "TypeScript"
114+
115+
Pass `{ skipTime: true }` to `setupTestEnvironment()`. The runner swaps its real timer
116+
for a queue that fires immediately. Both `context.wait()` delays and step retry delays
117+
complete in zero wall-clock time.
118+
119+
```typescript
120+
await LocalDurableTestRunner.setupTestEnvironment({ skipTime: true });
121+
```
122+
123+
=== "Python"
124+
125+
Set the `DURABLE_EXECUTION_TIME_SCALE` environment variable to a float that multiplies
126+
`context.wait()` durations. Set it to `0` for instant waits, or to a small fraction such
127+
as `0.01` to run waits at 100x speed. Step retry delays use the configured
128+
`next_attempt_delay_seconds` at real wall-clock time, and the scale does not apply to
129+
them. Keep retry delays short in tests, or configure a retry strategy with a low
130+
`initial_delay_seconds`.
131+
132+
```bash
133+
DURABLE_EXECUTION_TIME_SCALE=0 pytest tests/my_wait_tests.py
134+
```
135+
136+
=== "Java"
137+
138+
`runUntilComplete()` calls `advanceTime()` after each invocation. `advanceTime()`
139+
immediately marks PENDING step retries as READY and completes STARTED waits without
140+
real-time sleeps. If you call `run()` directly, call `advanceTime()` yourself between
141+
invocations.
142+
143+
```java
144+
runner.runUntilComplete(input); // advanceTime() runs after each invocation
145+
```
146+
147+
See [Workflow patterns: Long waits](workflow-patterns.md#long-waits) for a worked
148+
example.
149+
150+
## Test branching logic
151+
152+
Run the same handler with different inputs to cover each branch. Each test case gets its
153+
own runner instance.
154+
155+
=== "TypeScript"
156+
157+
```typescript
158+
--8<-- "examples/typescript/testing/authoring/test-branching.ts"
159+
```
160+
161+
=== "Python"
162+
163+
```python
164+
--8<-- "examples/python/testing/authoring/test-branching.py"
165+
```
166+
167+
=== "Java"
168+
169+
```java
170+
--8<-- "examples/java/testing/authoring/test-branching.java"
171+
```
172+
173+
## See also
174+
175+
- [API Reference](api-reference.md) Full reference for the runner, result, and operation
176+
classes.
177+
- [Workflow patterns](workflow-patterns.md) Complete tests for common workflow shapes.
178+
- [Assertions](assertions.md) Inspect steps, waits, and callbacks after a test run.
179+
- [Cloud Runner](cloud-runner.md) Run the same tests against a deployed Lambda function.
180+
- [SAM CLI](sam-cli.md) Local and remote invocation with SAM CLI.

0 commit comments

Comments
 (0)