Skip to content

Commit 6aca115

Browse files
authored
feat(testing-sdk): add ability to wait for submitted status for waitForCallback (#299)
*Issue #, if available:* #187 *Description of changes:* Currently the statuses for operation.waitForData only has STARTED and COMPLETED. Submitted is useful for waiting for after a waitForCallback has been submitted instead of just created. This allows the submitter to run to completion instead of having the callback be instantly completed while the submitter has not yet completed. 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 cfbd070 commit 6aca115

File tree

9 files changed

+397
-36
lines changed

9 files changed

+397
-36
lines changed

packages/aws-durable-execution-sdk-js-examples/src/examples/wait-for-callback/multiple-invocations/wait-for-callback-multiple-invocations.test.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,14 @@ createTests({
2020
payload: { test: "multiple-invocations" },
2121
});
2222

23-
// Wait for first callback and complete it
24-
await firstCallbackOp.waitForData(WaitingOperationStatus.STARTED);
25-
26-
// Give time for callback to be submitted (TODO: https://github.com/aws/aws-durable-execution-sdk-js/issues/187)
27-
await new Promise((resolve) => setTimeout(resolve, 1000));
23+
// Wait for first callback to be submitted, then complete it
24+
await firstCallbackOp.waitForData(WaitingOperationStatus.SUBMITTED);
2825

2926
const firstCallbackResult = JSON.stringify({ step: 1 });
3027
await firstCallbackOp.sendCallbackSuccess(firstCallbackResult);
3128

32-
// Wait for second callback and complete it
33-
await secondCallbackOp.waitForData(WaitingOperationStatus.STARTED);
34-
35-
// Give time for callback to be submitted (TODO: https://github.com/aws/aws-durable-execution-sdk-js/issues/187)
36-
await new Promise((resolve) => setTimeout(resolve, 1000));
29+
// Wait for second callback to be submitted, then complete it
30+
await secondCallbackOp.waitForData(WaitingOperationStatus.SUBMITTED);
3731

3832
const secondCallbackResult = JSON.stringify({ step: 2 });
3933
await secondCallbackOp.sendCallbackSuccess(secondCallbackResult);

packages/aws-durable-execution-sdk-js-testing/src/test-runner/cloud/cloud-durable-test-runner.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ export class CloudDurableTestRunner<ResultType>
4949
private readonly functionArn: string;
5050
private readonly client: LambdaClient;
5151
private readonly formatter = new ResultFormatter<ResultType>();
52-
private readonly waitManager = new OperationWaitManager();
5352
private indexedOperations = new IndexedOperations([]);
53+
private waitManager = new OperationWaitManager(this.indexedOperations);
5454
private operationStorage: OperationStorage;
5555
private readonly apiClient: DurableApiClient;
5656
private readonly config: CloudDurableTestRunnerConfigInternal;
@@ -190,6 +190,7 @@ export class CloudDurableTestRunner<ResultType>
190190

191191
reset() {
192192
this.indexedOperations = new IndexedOperations([]);
193+
this.waitManager = new OperationWaitManager(this.indexedOperations);
193194
this.operationStorage = new OperationStorage(
194195
this.waitManager,
195196
this.indexedOperations,

packages/aws-durable-execution-sdk-js-testing/src/test-runner/durable-test-runner.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,19 @@ import {
1313
import { OperationWithData } from "./common/operations/operation-with-data";
1414

1515
export enum WaitingOperationStatus {
16+
/**
17+
* Fires when the operation starts.
18+
*/
1619
STARTED = "STARTED",
20+
/**
21+
* Submitted is the same as COMPLETED, except for the case where the operation is waitForCallback.
22+
* In that case, SUBMITTED will fire when the waitForCallback submitter is completed.
23+
*/
24+
SUBMITTED = "SUBMITTED",
25+
/**
26+
* Fires when the operation is completed. This includes a status of CANCELLED, FAILED, STOPPED,
27+
* SUCCEEDED, or TIMED_OUT.
28+
*/
1729
COMPLETED = "COMPLETED",
1830
}
1931

packages/aws-durable-execution-sdk-js-testing/src/test-runner/local/__tests__/local-durable-test-runner.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { InvocationStatus } from "@aws/durable-execution-sdk-js";
88
import { CheckpointServerWorkerManager } from "../checkpoint-server-worker-manager";
99
import { CheckpointApiClient } from "../api-client/checkpoint-api-client";
1010
import { FunctionStorage } from "../operations/function-storage";
11+
import { IndexedOperations } from "../../common/indexed-operations";
1112
import { install } from "@sinonjs/fake-timers";
1213

1314
jest.mock("../test-execution-orchestrator");
@@ -122,7 +123,9 @@ describe("LocalDurableTestRunner", () => {
122123
});
123124

124125
expect(runner).toBeDefined();
125-
expect(OperationWaitManager).toHaveBeenCalledWith();
126+
expect(OperationWaitManager).toHaveBeenCalledWith(
127+
expect.any(IndexedOperations),
128+
);
126129
expect(LocalOperationStorage).toHaveBeenCalledWith(
127130
mockWaitManager,
128131
expect.any(Object),

packages/aws-durable-execution-sdk-js-testing/src/test-runner/local/local-durable-test-runner.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class LocalDurableTestRunner<ResultType>
9595
implements DurableTestRunner<OperationWithData, ResultType>
9696
{
9797
private operationStorage: LocalOperationStorage;
98-
private readonly waitManager: OperationWaitManager;
98+
private waitManager: OperationWaitManager;
9999
private readonly resultFormatter: ResultFormatter<ResultType>;
100100
private operationIndex: IndexedOperations;
101101
static skipTime = false;
@@ -111,8 +111,8 @@ export class LocalDurableTestRunner<ResultType>
111111
* @param params.handlerFunction The durable function handler to execute
112112
*/
113113
constructor({ handlerFunction }: LocalDurableTestRunnerParameters) {
114-
this.waitManager = new OperationWaitManager();
115114
this.operationIndex = new IndexedOperations([]);
115+
this.waitManager = new OperationWaitManager(this.operationIndex);
116116
this.resultFormatter = new ResultFormatter<ResultType>();
117117

118118
this.handlerFunction = handlerFunction;
@@ -307,6 +307,7 @@ export class LocalDurableTestRunner<ResultType>
307307

308308
reset() {
309309
this.operationIndex = new IndexedOperations([]);
310+
this.waitManager = new OperationWaitManager(this.operationIndex);
310311
this.operationStorage = new LocalOperationStorage(
311312
this.waitManager,
312313
this.operationIndex,

0 commit comments

Comments
 (0)