Skip to content

Commit 72858e7

Browse files
committed
Enhanced failure threshold exceeded tests with individual result assertions
- Added comprehensive individual result validation for map failure threshold exceeded count test - Added comprehensive individual result validation for map failure threshold exceeded percentage test - Verified proper status (SUCCEEDED/FAILED), index mapping, error types, and result values - Fixed TypeScript type assertions for accessing nested result payload structure - Tests now validate both overall completion reason and detailed individual item outcomes
1 parent 52f0668 commit 72858e7

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

packages/aws-durable-execution-sdk-js-examples/src/examples/map/failure-threshold-exceeded-count/map-failure-threshold-exceeded-count.test.ts

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,51 @@ createTests({
1010
const execution = await runner.run();
1111
const result = execution.getResult() as any;
1212

13-
console.log("DEBUG: Actual result:", JSON.stringify(result, null, 2));
14-
1513
expect(result.completionReason).toBe("FAILURE_TOLERANCE_EXCEEDED");
1614
expect(result.successCount).toBe(2); // Items 4 and 5 succeed
1715
expect(result.failureCount).toBe(3); // Items 1, 2, 3 fail (exceeds threshold of 2)
1816
expect(result.totalCount).toBe(5);
17+
18+
// Get the map context result from history
19+
const historyEvents = execution.getHistoryEvents();
20+
const mapContext = historyEvents.find(
21+
(event) =>
22+
event.EventType === "ContextSucceeded" &&
23+
event.Name === "failure-threshold-items",
24+
);
25+
26+
expect(mapContext).toBeDefined();
27+
expect(
28+
mapContext?.ContextSucceededDetails?.Result?.Payload,
29+
).toBeDefined();
30+
const mapResult = JSON.parse(
31+
mapContext!.ContextSucceededDetails!.Result!.Payload!,
32+
);
33+
34+
// Verify individual results
35+
expect(mapResult.all).toHaveLength(5);
36+
37+
// Items 0, 1, 2 should fail
38+
expect(mapResult.all[0].status).toBe("FAILED");
39+
expect(mapResult.all[0].index).toBe(0);
40+
expect(mapResult.all[0].error.errorType).toBe("ChildContextError");
41+
42+
expect(mapResult.all[1].status).toBe("FAILED");
43+
expect(mapResult.all[1].index).toBe(1);
44+
expect(mapResult.all[1].error.errorType).toBe("ChildContextError");
45+
46+
expect(mapResult.all[2].status).toBe("FAILED");
47+
expect(mapResult.all[2].index).toBe(2);
48+
expect(mapResult.all[2].error.errorType).toBe("ChildContextError");
49+
50+
// Items 3, 4 should succeed
51+
expect(mapResult.all[3].status).toBe("SUCCEEDED");
52+
expect(mapResult.all[3].index).toBe(3);
53+
expect(mapResult.all[3].result).toBe(8); // 4 * 2
54+
55+
expect(mapResult.all[4].status).toBe("SUCCEEDED");
56+
expect(mapResult.all[4].index).toBe(4);
57+
expect(mapResult.all[4].result).toBe(10); // 5 * 2
1958
});
2059
},
2160
});

packages/aws-durable-execution-sdk-js-examples/src/examples/map/failure-threshold-exceeded-percentage/map-failure-threshold-exceeded-percentage.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,47 @@ createTests({
1414
expect(result.successCount).toBe(2); // Items 4 and 5 succeed
1515
expect(result.failureCount).toBe(3); // Items 1, 2, 3 fail (60% > 50% threshold)
1616
expect(result.totalCount).toBe(5);
17+
18+
// Get the map context result from history
19+
const historyEvents = execution.getHistoryEvents();
20+
const mapContext = historyEvents.find(
21+
(event) =>
22+
event.EventType === "ContextSucceeded" &&
23+
event.Name === "failure-threshold-items",
24+
);
25+
26+
expect(mapContext).toBeDefined();
27+
expect(
28+
mapContext?.ContextSucceededDetails?.Result?.Payload,
29+
).toBeDefined();
30+
const mapResult = JSON.parse(
31+
mapContext!.ContextSucceededDetails!.Result!.Payload!,
32+
);
33+
34+
// Verify individual results
35+
expect(mapResult.all).toHaveLength(5);
36+
37+
// Items 0, 1, 2 should fail
38+
expect(mapResult.all[0].status).toBe("FAILED");
39+
expect(mapResult.all[0].index).toBe(0);
40+
expect(mapResult.all[0].error.errorType).toBe("ChildContextError");
41+
42+
expect(mapResult.all[1].status).toBe("FAILED");
43+
expect(mapResult.all[1].index).toBe(1);
44+
expect(mapResult.all[1].error.errorType).toBe("ChildContextError");
45+
46+
expect(mapResult.all[2].status).toBe("FAILED");
47+
expect(mapResult.all[2].index).toBe(2);
48+
expect(mapResult.all[2].error.errorType).toBe("ChildContextError");
49+
50+
// Items 3, 4 should succeed
51+
expect(mapResult.all[3].status).toBe("SUCCEEDED");
52+
expect(mapResult.all[3].index).toBe(3);
53+
expect(mapResult.all[3].result).toBe(8); // 4 * 2
54+
55+
expect(mapResult.all[4].status).toBe("SUCCEEDED");
56+
expect(mapResult.all[4].index).toBe(4);
57+
expect(mapResult.all[4].result).toBe(10); // 5 * 2
1758
});
1859
},
1960
});

0 commit comments

Comments
 (0)