Skip to content

Commit e4cfd60

Browse files
committed
fix: give unique name to min-successful-with-passing-threshold test
Changed config.name from 'Parallel minSuccessful' to 'Parallel minSuccessful with Passing Threshold' to avoid Lambda function mapping conflict with the existing parallel-min-successful test.
1 parent 72f3c5d commit e4cfd60

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { handler } from "./min-successful-with-passing-threshold";
2+
import { createTests } from "../../../utils/test-helper";
3+
import { OperationStatus } from "@aws/durable-execution-sdk-js-testing";
4+
5+
createTests({
6+
localRunnerConfig: {
7+
skipTime: false,
8+
checkpointDelay: 100,
9+
},
10+
handler,
11+
tests: (runner) => {
12+
it("should complete early when minSuccessful is reached", async () => {
13+
const execution = await runner.run();
14+
const result = execution.getResult() as any;
15+
16+
// Assert overall results
17+
expect(result.successCount).toBe(2);
18+
expect(result.completionReason).toBe("MIN_SUCCESSFUL_REACHED");
19+
expect(result.totalCount).toBe(5);
20+
21+
// Get the parallel operation to verify individual branch results
22+
// Get individual branch operations
23+
const branch1 = runner.getOperation("branch-1");
24+
const branch2 = runner.getOperation("branch-2");
25+
const branch3 = runner.getOperation("branch-3");
26+
const branch4 = runner.getOperation("branch-4");
27+
const branch5 = runner.getOperation("branch-5");
28+
29+
// First two branches should succeed (branch-1 and branch-2 complete fastest)
30+
expect(branch1?.getStatus()).toBe(OperationStatus.SUCCEEDED);
31+
expect(branch2?.getStatus()).toBe(OperationStatus.SUCCEEDED);
32+
expect(branch3?.getStatus()).toBe(OperationStatus.SUCCEEDED);
33+
expect(branch4?.getStatus()).toBe(OperationStatus.SUCCEEDED);
34+
35+
// Remaining branches should be in STARTED state (not completed)
36+
expect(branch5?.getStatus()).toBe(OperationStatus.STARTED);
37+
38+
// Verify the results array matches
39+
expect(result.results).toEqual(["Branch 1 result", "Branch 2 result"]);
40+
});
41+
},
42+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import {
2+
DurableContext,
3+
withDurableExecution,
4+
} from "@aws/durable-execution-sdk-js";
5+
import { ExampleConfig } from "../../../types";
6+
import { log } from "../../../utils/logger";
7+
8+
export const config: ExampleConfig = {
9+
name: "Parallel minSuccessful with Passing Threshold",
10+
description:
11+
"Parallel execution with minSuccessful completion config and passing threshold",
12+
};
13+
14+
export const handler = withDurableExecution(
15+
async (event: any, context: DurableContext) => {
16+
log("Starting parallel execution with minSuccessful: 2");
17+
18+
// First brach finishes first
19+
// Branch 2 to 4 finish in the same time
20+
// Branc 5 will finish later
21+
const results = await context.parallel(
22+
"min-successful-branches",
23+
[
24+
{
25+
name: "branch-1",
26+
func: async (ctx) => {
27+
return await ctx.step("branch-1", async () => {
28+
await new Promise((resolve) => setTimeout(resolve, 10));
29+
return "Branch 1 result";
30+
});
31+
},
32+
},
33+
{
34+
name: "branch-2",
35+
func: async (ctx) => {
36+
return await ctx.step("branch-2", async () => {
37+
await new Promise((resolve) => setTimeout(resolve, 50));
38+
return "Branch 2 result";
39+
});
40+
},
41+
},
42+
{
43+
name: "branch-3",
44+
func: async (ctx) => {
45+
return await ctx.step("branch-3", async () => {
46+
await new Promise((resolve) => setTimeout(resolve, 50));
47+
return "Branch 3 result";
48+
});
49+
},
50+
},
51+
{
52+
name: "branch-4",
53+
func: async (ctx) => {
54+
return await ctx.step("branch-4", async () => {
55+
await new Promise((resolve) => setTimeout(resolve, 50));
56+
return "Branch 4 result";
57+
});
58+
},
59+
},
60+
{
61+
name: "branch-5",
62+
func: async (ctx) => {
63+
return await ctx.step("branch-4", async () => {
64+
await new Promise((resolve) => setTimeout(resolve, 2000));
65+
return "Branch 4 result";
66+
});
67+
},
68+
},
69+
],
70+
{
71+
completionConfig: {
72+
minSuccessful: 2,
73+
},
74+
},
75+
);
76+
77+
await context.wait({ seconds: 1 });
78+
79+
log(`Completed with ${results.successCount} successes`);
80+
log(`Completion reason: ${results.completionReason}`);
81+
82+
return {
83+
successCount: results.successCount,
84+
totalCount: results.totalCount,
85+
completionReason: results.completionReason,
86+
results: results.getResults(),
87+
};
88+
},
89+
);

0 commit comments

Comments
 (0)