Skip to content

Commit 28e5623

Browse files
authored
ci: add more concurrency examples (#404)
*Issue #, if available:* Closes #265, #234, #188 *Description of changes:* Adding examples for concurrency examples that used to not work, but are fixed now. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent 9086fd7 commit 28e5623

File tree

9 files changed

+705
-0
lines changed

9 files changed

+705
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
[
2+
{
3+
"EventType": "ExecutionStarted",
4+
"EventId": 1,
5+
"Id": "78d73735-f746-4ad6-9701-9a22dd29b729",
6+
"EventTimestamp": "2025-12-22T21:51:48.345Z",
7+
"ExecutionStartedDetails": {
8+
"Input": {
9+
"Payload": "{}"
10+
}
11+
}
12+
},
13+
{
14+
"EventType": "ContextStarted",
15+
"SubType": "Parallel",
16+
"EventId": 2,
17+
"Id": "c4ca4238a0b92382",
18+
"EventTimestamp": "2025-12-22T21:51:48.352Z",
19+
"ContextStartedDetails": {}
20+
},
21+
{
22+
"EventType": "ContextStarted",
23+
"SubType": "ParallelBranch",
24+
"EventId": 3,
25+
"Id": "ea66c06c1e1c05fa",
26+
"Name": "parallel-branch-0",
27+
"EventTimestamp": "2025-12-22T21:51:48.352Z",
28+
"ParentId": "c4ca4238a0b92382",
29+
"ContextStartedDetails": {}
30+
},
31+
{
32+
"EventType": "ContextStarted",
33+
"SubType": "WaitForCallback",
34+
"EventId": 4,
35+
"Id": "2f221a18eb863803",
36+
"Name": "wait-for-callback-1",
37+
"EventTimestamp": "2025-12-22T21:51:48.352Z",
38+
"ParentId": "ea66c06c1e1c05fa",
39+
"ContextStartedDetails": {}
40+
},
41+
{
42+
"EventType": "CallbackStarted",
43+
"SubType": "Callback",
44+
"EventId": 5,
45+
"Id": "55998bab939d40e7",
46+
"EventTimestamp": "2025-12-22T21:51:48.352Z",
47+
"ParentId": "2f221a18eb863803",
48+
"CallbackStartedDetails": {
49+
"CallbackId": "eyJleGVjdXRpb25JZCI6ImQxMjQ1YmFlLTVlZTgtNGE2Yi1iNTEyLThjZDVmNTg5YmJiYiIsIm9wZXJhdGlvbklkIjoiNTU5OThiYWI5MzlkNDBlNyIsInRva2VuIjoiYzViMGUxOTgtNjZiOC00ZWFkLWFkYTItZjEwZmU3NWI3NTI4In0=",
50+
"Input": {}
51+
}
52+
},
53+
{
54+
"EventType": "ContextStarted",
55+
"SubType": "ParallelBranch",
56+
"EventId": 6,
57+
"Id": "98c6f2c2287f4c73",
58+
"Name": "parallel-branch-1",
59+
"EventTimestamp": "2025-12-22T21:51:48.352Z",
60+
"ParentId": "c4ca4238a0b92382",
61+
"ContextStartedDetails": {}
62+
},
63+
{
64+
"EventType": "ContextStarted",
65+
"SubType": "WaitForCallback",
66+
"EventId": 7,
67+
"Id": "6151f5ab282d90e4",
68+
"Name": "wait-for-callback-2",
69+
"EventTimestamp": "2025-12-22T21:51:48.352Z",
70+
"ParentId": "98c6f2c2287f4c73",
71+
"ContextStartedDetails": {}
72+
},
73+
{
74+
"EventType": "CallbackStarted",
75+
"SubType": "Callback",
76+
"EventId": 8,
77+
"Id": "361fe970d1e192e9",
78+
"EventTimestamp": "2025-12-22T21:51:48.352Z",
79+
"ParentId": "6151f5ab282d90e4",
80+
"CallbackStartedDetails": {
81+
"CallbackId": "eyJleGVjdXRpb25JZCI6ImQxMjQ1YmFlLTVlZTgtNGE2Yi1iNTEyLThjZDVmNTg5YmJiYiIsIm9wZXJhdGlvbklkIjoiMzYxZmU5NzBkMWUxOTJlOSIsInRva2VuIjoiM2ZhZjljMzUtY2NmMS00MzdhLWI0N2QtZmUzNTA2ZTBkNDJiIn0=",
82+
"Input": {}
83+
}
84+
},
85+
{
86+
"EventType": "CallbackSucceeded",
87+
"SubType": "Callback",
88+
"EventId": 9,
89+
"Id": "361fe970d1e192e9",
90+
"EventTimestamp": "2025-12-22T21:51:48.354Z",
91+
"ParentId": "6151f5ab282d90e4",
92+
"CallbackSucceededDetails": {
93+
"Result": {
94+
"Payload": "{\"id\":2,\"data\":\"second-completed\"}"
95+
}
96+
}
97+
},
98+
{
99+
"EventType": "CallbackSucceeded",
100+
"SubType": "Callback",
101+
"EventId": 10,
102+
"Id": "55998bab939d40e7",
103+
"EventTimestamp": "2025-12-22T21:51:48.354Z",
104+
"ParentId": "2f221a18eb863803",
105+
"CallbackSucceededDetails": {
106+
"Result": {
107+
"Payload": "{\"id\":1,\"data\":\"first-completed\"}"
108+
}
109+
}
110+
},
111+
{
112+
"EventType": "StepStarted",
113+
"SubType": "Step",
114+
"EventId": 11,
115+
"Id": "90ef5a310191970a",
116+
"EventTimestamp": "2025-12-22T21:51:48.355Z",
117+
"ParentId": "2f221a18eb863803",
118+
"StepStartedDetails": {}
119+
},
120+
{
121+
"EventType": "StepStarted",
122+
"SubType": "Step",
123+
"EventId": 12,
124+
"Id": "1c573df7b335bdcb",
125+
"EventTimestamp": "2025-12-22T21:51:48.355Z",
126+
"ParentId": "6151f5ab282d90e4",
127+
"StepStartedDetails": {}
128+
},
129+
{
130+
"EventType": "StepSucceeded",
131+
"SubType": "Step",
132+
"EventId": 13,
133+
"Id": "1c573df7b335bdcb",
134+
"EventTimestamp": "2025-12-22T21:51:48.355Z",
135+
"ParentId": "6151f5ab282d90e4",
136+
"StepSucceededDetails": {
137+
"Result": {},
138+
"RetryDetails": {}
139+
}
140+
},
141+
{
142+
"EventType": "ContextSucceeded",
143+
"SubType": "WaitForCallback",
144+
"EventId": 14,
145+
"Id": "6151f5ab282d90e4",
146+
"Name": "wait-for-callback-2",
147+
"EventTimestamp": "2025-12-22T21:51:48.357Z",
148+
"ParentId": "98c6f2c2287f4c73",
149+
"ContextSucceededDetails": {
150+
"Result": {
151+
"Payload": "\"{\\\"id\\\":2,\\\"data\\\":\\\"second-completed\\\"}\""
152+
}
153+
}
154+
},
155+
{
156+
"EventType": "ContextSucceeded",
157+
"SubType": "ParallelBranch",
158+
"EventId": 15,
159+
"Id": "98c6f2c2287f4c73",
160+
"Name": "parallel-branch-1",
161+
"EventTimestamp": "2025-12-22T21:51:48.357Z",
162+
"ParentId": "c4ca4238a0b92382",
163+
"ContextSucceededDetails": {
164+
"Result": {
165+
"Payload": "\"{\\\"id\\\":2,\\\"data\\\":\\\"second-completed\\\"}\""
166+
}
167+
}
168+
},
169+
{
170+
"EventType": "StepSucceeded",
171+
"SubType": "Step",
172+
"EventId": 16,
173+
"Id": "90ef5a310191970a",
174+
"EventTimestamp": "2025-12-22T21:51:50.357Z",
175+
"ParentId": "2f221a18eb863803",
176+
"StepSucceededDetails": {
177+
"Result": {},
178+
"RetryDetails": {}
179+
}
180+
},
181+
{
182+
"EventType": "ContextSucceeded",
183+
"SubType": "WaitForCallback",
184+
"EventId": 17,
185+
"Id": "2f221a18eb863803",
186+
"Name": "wait-for-callback-1",
187+
"EventTimestamp": "2025-12-22T21:51:50.366Z",
188+
"ParentId": "ea66c06c1e1c05fa",
189+
"ContextSucceededDetails": {
190+
"Result": {
191+
"Payload": "\"{\\\"id\\\":1,\\\"data\\\":\\\"first-completed\\\"}\""
192+
}
193+
}
194+
},
195+
{
196+
"EventType": "ContextSucceeded",
197+
"SubType": "ParallelBranch",
198+
"EventId": 18,
199+
"Id": "ea66c06c1e1c05fa",
200+
"Name": "parallel-branch-0",
201+
"EventTimestamp": "2025-12-22T21:51:50.366Z",
202+
"ParentId": "c4ca4238a0b92382",
203+
"ContextSucceededDetails": {
204+
"Result": {
205+
"Payload": "\"{\\\"id\\\":1,\\\"data\\\":\\\"first-completed\\\"}\""
206+
}
207+
}
208+
},
209+
{
210+
"EventType": "ContextSucceeded",
211+
"SubType": "Parallel",
212+
"EventId": 19,
213+
"Id": "c4ca4238a0b92382",
214+
"EventTimestamp": "2025-12-22T21:51:50.366Z",
215+
"ContextSucceededDetails": {
216+
"Result": {
217+
"Payload": "{\"all\":[{\"result\":\"{\\\"id\\\":1,\\\"data\\\":\\\"first-completed\\\"}\",\"index\":0,\"status\":\"SUCCEEDED\"},{\"result\":\"{\\\"id\\\":2,\\\"data\\\":\\\"second-completed\\\"}\",\"index\":1,\"status\":\"SUCCEEDED\"}],\"completionReason\":\"ALL_COMPLETED\"}"
218+
}
219+
}
220+
},
221+
{
222+
"EventType": "InvocationCompleted",
223+
"EventId": 20,
224+
"EventTimestamp": "2025-12-22T21:51:50.367Z",
225+
"InvocationCompletedDetails": {
226+
"StartTimestamp": "2025-12-22T21:51:48.344Z",
227+
"EndTimestamp": "2025-12-22T21:51:50.367Z",
228+
"Error": {},
229+
"RequestId": "3835e53e-7f26-4ebb-b9ab-d705ef995ce2"
230+
}
231+
},
232+
{
233+
"EventType": "ExecutionSucceeded",
234+
"EventId": 21,
235+
"Id": "78d73735-f746-4ad6-9701-9a22dd29b729",
236+
"EventTimestamp": "2025-12-22T21:51:50.368Z",
237+
"ExecutionSucceededDetails": {
238+
"Result": {
239+
"Payload": "{\"results\":[{\"id\":1,\"data\":\"first-completed\"},{\"id\":2,\"data\":\"second-completed\"}],\"allCompleted\":true}"
240+
}
241+
}
242+
}
243+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { InvocationType } from "@aws/durable-execution-sdk-js-testing";
2+
import { handler } from "./concurrent-callback-submitter";
3+
import { createTests } from "../../../utils/test-helper";
4+
5+
createTests({
6+
handler,
7+
invocationType: InvocationType.Event,
8+
tests: (runner, { assertEventSignatures }) => {
9+
it("should handle multiple concurrent waitForCallback operations", async () => {
10+
const callback1Op = runner.getOperation("wait-for-callback-1");
11+
const callback2Op = runner.getOperation("wait-for-callback-2");
12+
13+
const executionPromise = runner.run();
14+
15+
await Promise.all([callback1Op.waitForData(), callback2Op.waitForData()]);
16+
17+
const callback2Result = JSON.stringify({
18+
id: 2,
19+
data: "second-completed",
20+
});
21+
const callback1Result = JSON.stringify({
22+
id: 1,
23+
data: "first-completed",
24+
});
25+
26+
// Ensure invocation completes
27+
await new Promise((resolve) => setTimeout(resolve, 100));
28+
29+
await callback2Op.sendCallbackSuccess(callback2Result);
30+
await callback1Op.sendCallbackSuccess(callback1Result);
31+
32+
const execution = await executionPromise;
33+
34+
assertEventSignatures(execution);
35+
});
36+
},
37+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {
2+
withDurableExecution,
3+
DurableContext,
4+
} from "@aws/durable-execution-sdk-js";
5+
import { ExampleConfig } from "../../../types";
6+
7+
export const config: ExampleConfig = {
8+
name: "Concurrent Callback with Submitter",
9+
description:
10+
"Demonstrates waitForCallback with submitter function inside context.parallel",
11+
};
12+
13+
export const handler = withDurableExecution(
14+
async (event: unknown, context: DurableContext) => {
15+
const parallelResult = await context.parallel([
16+
(childContext) =>
17+
childContext.waitForCallback<string>(
18+
"wait-for-callback-1",
19+
async () => {
20+
await new Promise((resolve) => setTimeout(resolve, 2000));
21+
return Promise.resolve();
22+
},
23+
),
24+
(childContext) =>
25+
childContext.waitForCallback<string>(
26+
"wait-for-callback-2",
27+
async () => {
28+
return Promise.resolve();
29+
},
30+
),
31+
]);
32+
33+
const [result1, result2] = parallelResult
34+
.getResults()
35+
.map((result) => JSON.parse(result));
36+
37+
return {
38+
results: [result1, result2],
39+
allCompleted: true,
40+
};
41+
},
42+
);

0 commit comments

Comments
 (0)