Skip to content

Commit 42dc7f7

Browse files
committed
fix(sdk): remove termination cooldown
1 parent 99e4a67 commit 42dc7f7

File tree

4 files changed

+34
-25
lines changed

4 files changed

+34
-25
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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { createTests } from "../../../utils/test-helper";
88
createTests({
99
handler,
1010
invocationType: InvocationType.Event,
11+
localRunnerConfig: {
12+
skipTime: false,
13+
},
1114
tests: (runner, { assertEventSignatures }) => {
1215
it("should handle multiple invocations tracking with waitForCallback operations", async () => {
1316
// Get operations for verification
@@ -39,11 +42,9 @@ createTests({
3942
invocationCount: "multiple",
4043
});
4144

42-
// Verify invocations were tracked - should be 4-5 invocations
43-
// Due to update/termination timing, this execution may require 4-5 invocations to complete
45+
// Verify invocations were tracked - should be exactly 5 invocations
4446
const invocations = result.getInvocations();
45-
expect(invocations.length).toBeGreaterThanOrEqual(4);
46-
expect(invocations.length).toBeLessThanOrEqual(5);
47+
expect(invocations.length).toBe(5);
4748

4849
// Verify operations were executed
4950
const operations = result.getOperations();

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,9 @@ describe("LocalDurableTestRunner Integration", () => {
8989
// Verify that operations were tracked
9090
const operations = result.getOperations();
9191

92-
// Verify the invocations were tracked - should be exactly 2 invocations
93-
// Centralized termination implements a cool-down period prior to termination.
94-
// This cool-down phase reduces the total number of invocations needed while increasing
95-
// the number of operations performed in each invocation.
92+
// Verify the invocations were tracked - should be exactly 3 invocations
9693
const invocations = result.getInvocations();
97-
expect(invocations).toHaveLength(2);
94+
expect(invocations).toHaveLength(3);
9895

9996
// We should have 3 operations in total
10097
expect(operations).toHaveLength(3);
@@ -229,8 +226,19 @@ describe("LocalDurableTestRunner Integration", () => {
229226
},
230227
},
231228
{
232-
EventType: "ExecutionSucceeded",
229+
EventType: "InvocationCompleted",
233230
EventId: 10,
231+
EventTimestamp: expect.any(Date),
232+
InvocationCompletedDetails: {
233+
StartTimestamp: expect.any(Date),
234+
EndTimestamp: expect.any(Date),
235+
Error: {},
236+
RequestId: expect.any(String),
237+
},
238+
},
239+
{
240+
EventType: "ExecutionSucceeded",
241+
EventId: 11,
234242
Id: expect.any(String),
235243
EventTimestamp: expect.any(Date),
236244
ExecutionSucceededDetails: {

packages/aws-durable-execution-sdk-js/src/utils/checkpoint/checkpoint-central-termination.test.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ describe("CheckpointManager - Centralized Termination", () => {
270270
);
271271

272272
// Advance past cooldown
273-
jest.advanceTimersByTime(50);
273+
jest.advanceTimersByTime(0);
274274

275275
expect(mockTerminationManager.terminate).toHaveBeenCalledWith({
276276
reason: TerminationReason.WAIT_SCHEDULED,
@@ -290,8 +290,8 @@ describe("CheckpointManager - Centralized Termination", () => {
290290
},
291291
);
292292

293-
// Advance partway through cooldown
294-
jest.advanceTimersByTime(25);
293+
// No time advancement so the setTimeout will get cancelled from synchronous code
294+
expect(mockTerminationManager.terminate).not.toHaveBeenCalled();
295295

296296
// Start new operation
297297
checkpointManager.markOperationState(
@@ -306,10 +306,11 @@ describe("CheckpointManager - Centralized Termination", () => {
306306
},
307307
);
308308

309+
expect(mockTerminationManager.terminate).not.toHaveBeenCalled();
310+
309311
// Advance past original cooldown
310-
jest.advanceTimersByTime(50);
312+
jest.advanceTimersByTime(0);
311313

312-
// Should not have terminated
313314
expect(mockTerminationManager.terminate).not.toHaveBeenCalled();
314315
});
315316
});
@@ -340,7 +341,7 @@ describe("CheckpointManager - Centralized Termination", () => {
340341
},
341342
);
342343

343-
jest.advanceTimersByTime(200);
344+
jest.advanceTimersByTime(0);
344345

345346
expect(mockTerminationManager.terminate).toHaveBeenCalledWith({
346347
reason: TerminationReason.RETRY_SCHEDULED,
@@ -372,7 +373,7 @@ describe("CheckpointManager - Centralized Termination", () => {
372373
},
373374
);
374375

375-
jest.advanceTimersByTime(200);
376+
jest.advanceTimersByTime(0);
376377

377378
expect(mockTerminationManager.terminate).toHaveBeenCalledWith({
378379
reason: TerminationReason.WAIT_SCHEDULED,
@@ -392,7 +393,7 @@ describe("CheckpointManager - Centralized Termination", () => {
392393
},
393394
);
394395

395-
jest.advanceTimersByTime(200);
396+
jest.advanceTimersByTime(0);
396397

397398
expect(mockTerminationManager.terminate).toHaveBeenCalledWith({
398399
reason: TerminationReason.CALLBACK_PENDING,
@@ -677,7 +678,7 @@ describe("CheckpointManager - Centralized Termination", () => {
677678
(checkpointManager as any).checkAndTerminate();
678679

679680
// Should not terminate
680-
jest.advanceTimersByTime(300);
681+
jest.advanceTimersByTime(0);
681682
expect(mockTerminationManager.terminate).not.toHaveBeenCalled();
682683
});
683684

@@ -701,7 +702,7 @@ describe("CheckpointManager - Centralized Termination", () => {
701702
(checkpointManager as any).checkAndTerminate();
702703

703704
// Should not terminate
704-
jest.advanceTimersByTime(300);
705+
jest.advanceTimersByTime(0);
705706
expect(mockTerminationManager.terminate).not.toHaveBeenCalled();
706707
});
707708

@@ -725,7 +726,7 @@ describe("CheckpointManager - Centralized Termination", () => {
725726
(checkpointManager as any).checkAndTerminate();
726727

727728
// Should not terminate
728-
jest.advanceTimersByTime(300);
729+
jest.advanceTimersByTime(0);
729730
expect(mockTerminationManager.terminate).not.toHaveBeenCalled();
730731
});
731732

@@ -758,7 +759,7 @@ describe("CheckpointManager - Centralized Termination", () => {
758759
(checkpointManager as any).checkAndTerminate();
759760

760761
// Should not terminate
761-
jest.advanceTimersByTime(300);
762+
jest.advanceTimersByTime(0);
762763
expect(mockTerminationManager.terminate).not.toHaveBeenCalled();
763764
});
764765

packages/aws-durable-execution-sdk-js/src/utils/checkpoint/checkpoint-manager.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export class CheckpointManager implements Checkpoint {
5151
// Termination cooldown
5252
private terminationTimer: NodeJS.Timeout | null = null;
5353
private terminationReason: TerminationReason | null = null;
54-
private readonly TERMINATION_COOLDOWN_MS = 50;
5554

5655
constructor(
5756
private durableExecutionArn: string,
@@ -714,12 +713,12 @@ export class CheckpointManager implements Checkpoint {
714713
this.terminationReason = reason;
715714
log("⏱️", "Scheduling termination", {
716715
reason,
717-
cooldownMs: this.TERMINATION_COOLDOWN_MS,
718716
});
719717

718+
// Schedule termination immediately once event loop is free.
720719
this.terminationTimer = setTimeout(() => {
721720
this.executeTermination(reason);
722-
}, this.TERMINATION_COOLDOWN_MS);
721+
}, 0);
723722
}
724723

725724
private executeTermination(reason: TerminationReason): void {

0 commit comments

Comments
 (0)