Skip to content

Commit 4bed68a

Browse files
committed
unit test fix
1 parent 8177102 commit 4bed68a

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

packages/durabletask-js/test/orchestration_executor.spec.ts

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -822,12 +822,12 @@ describe("Orchestration Executor", () => {
822822
newOrchestratorStartedEvent(),
823823
newExecutionStartedEvent(name, TEST_INSTANCE_ID, JSON.stringify(21)),
824824
];
825-
let actions = await executor.execute(TEST_INSTANCE_ID, [], newEvents);
825+
let result = await executor.execute(TEST_INSTANCE_ID, [], newEvents);
826826

827827
// Assert - Step 1: Should schedule activity
828-
expect(actions.length).toBe(1);
829-
expect(actions[0].hasScheduletask()).toBe(true);
830-
expect(actions[0].getScheduletask()?.getName()).toBe("flakyActivity");
828+
expect(result.actions.length).toBe(1);
829+
expect(result.actions[0].hasScheduletask()).toBe(true);
830+
expect(result.actions[0].getScheduletask()?.getName()).toBe("flakyActivity");
831831

832832
// Act - Step 2: Activity scheduled, then fails
833833
const oldEvents = [
@@ -838,11 +838,11 @@ describe("Orchestration Executor", () => {
838838
newEvents = [
839839
newTaskFailedEvent(1, new Error("Transient failure on attempt 1")),
840840
];
841-
actions = await executor.execute(TEST_INSTANCE_ID, oldEvents, newEvents);
841+
result = await executor.execute(TEST_INSTANCE_ID, oldEvents, newEvents);
842842

843843
// Assert - Step 2: Should schedule a retry timer
844-
expect(actions.length).toBe(1);
845-
expect(actions[0].hasCreatetimer()).toBe(true);
844+
expect(result.actions.length).toBe(1);
845+
expect(result.actions[0].hasCreatetimer()).toBe(true);
846846
});
847847

848848
it("should complete successfully after retry timer fires and activity succeeds", async () => {
@@ -869,44 +869,44 @@ describe("Orchestration Executor", () => {
869869
newOrchestratorStartedEvent(startTime),
870870
newExecutionStartedEvent(name, TEST_INSTANCE_ID, JSON.stringify(21)),
871871
];
872-
let actions = await executor.execute(TEST_INSTANCE_ID, [], allEvents);
873-
expect(actions.length).toBe(1);
874-
expect(actions[0].hasScheduletask()).toBe(true);
872+
let result = await executor.execute(TEST_INSTANCE_ID, [], allEvents);
873+
expect(result.actions.length).toBe(1);
874+
expect(result.actions[0].hasScheduletask()).toBe(true);
875875

876876
// Step 2: Activity scheduled, then fails
877877
allEvents.push(newTaskScheduledEvent(1, "flakyActivity"));
878878
executor = new OrchestrationExecutor(registry);
879-
actions = await executor.execute(TEST_INSTANCE_ID, allEvents, [
879+
result = await executor.execute(TEST_INSTANCE_ID, allEvents, [
880880
newTaskFailedEvent(1, new Error("Transient failure on attempt 1")),
881881
]);
882-
expect(actions.length).toBe(1);
883-
expect(actions[0].hasCreatetimer()).toBe(true);
884-
const timerFireAt = actions[0].getCreatetimer()?.getFireat()?.toDate();
882+
expect(result.actions.length).toBe(1);
883+
expect(result.actions[0].hasCreatetimer()).toBe(true);
884+
const timerFireAt = result.actions[0].getCreatetimer()?.getFireat()?.toDate();
885885
expect(timerFireAt).toBeDefined();
886886

887887
// Step 3: Timer created, then fires
888888
allEvents.push(newTaskFailedEvent(1, new Error("Transient failure on attempt 1")));
889889
allEvents.push(newTimerCreatedEvent(2, timerFireAt!));
890890
executor = new OrchestrationExecutor(registry);
891-
actions = await executor.execute(TEST_INSTANCE_ID, allEvents, [
891+
result = await executor.execute(TEST_INSTANCE_ID, allEvents, [
892892
newTimerFiredEvent(2, timerFireAt!),
893893
]);
894894
// Should reschedule the activity with a new ID
895-
expect(actions.length).toBe(1);
896-
expect(actions[0].hasScheduletask()).toBe(true);
897-
expect(actions[0].getScheduletask()?.getName()).toBe("flakyActivity");
898-
expect(actions[0].getId()).toBe(3); // New ID after timer
895+
expect(result.actions.length).toBe(1);
896+
expect(result.actions[0].hasScheduletask()).toBe(true);
897+
expect(result.actions[0].getScheduletask()?.getName()).toBe("flakyActivity");
898+
expect(result.actions[0].getId()).toBe(3); // New ID after timer
899899

900900
// Step 4: Retried activity scheduled, then completes
901901
allEvents.push(newTimerFiredEvent(2, timerFireAt!));
902902
allEvents.push(newTaskScheduledEvent(3, "flakyActivity"));
903903
executor = new OrchestrationExecutor(registry);
904-
actions = await executor.execute(TEST_INSTANCE_ID, allEvents, [
904+
result = await executor.execute(TEST_INSTANCE_ID, allEvents, [
905905
newTaskCompletedEvent(3, JSON.stringify(42)),
906906
]);
907907

908908
// Assert: Orchestration should complete successfully
909-
const completeAction = getAndValidateSingleCompleteOrchestrationAction(actions);
909+
const completeAction = getAndValidateSingleCompleteOrchestrationAction(result);
910910
expect(completeAction?.getOrchestrationstatus()).toEqual(pb.OrchestrationStatus.ORCHESTRATION_STATUS_COMPLETED);
911911
expect(completeAction?.getResult()?.getValue()).toEqual(JSON.stringify(42));
912912
});
@@ -935,40 +935,40 @@ describe("Orchestration Executor", () => {
935935
newOrchestratorStartedEvent(startTime),
936936
newExecutionStartedEvent(name, TEST_INSTANCE_ID, JSON.stringify(21)),
937937
];
938-
let actions = await executor.execute(TEST_INSTANCE_ID, [], allEvents);
939-
expect(actions.length).toBe(1);
940-
expect(actions[0].hasScheduletask()).toBe(true);
938+
let result = await executor.execute(TEST_INSTANCE_ID, [], allEvents);
939+
expect(result.actions.length).toBe(1);
940+
expect(result.actions[0].hasScheduletask()).toBe(true);
941941

942942
// Step 2: Activity fails - first attempt
943943
allEvents.push(newTaskScheduledEvent(1, "alwaysFailsActivity"));
944944
executor = new OrchestrationExecutor(registry);
945-
actions = await executor.execute(TEST_INSTANCE_ID, allEvents, [
945+
result = await executor.execute(TEST_INSTANCE_ID, allEvents, [
946946
newTaskFailedEvent(1, new Error("Failure on attempt 1")),
947947
]);
948-
expect(actions.length).toBe(1);
949-
expect(actions[0].hasCreatetimer()).toBe(true);
950-
const timerFireAt = actions[0].getCreatetimer()?.getFireat()?.toDate();
948+
expect(result.actions.length).toBe(1);
949+
expect(result.actions[0].hasCreatetimer()).toBe(true);
950+
const timerFireAt = result.actions[0].getCreatetimer()?.getFireat()?.toDate();
951951

952952
// Step 3: Timer fires, activity is rescheduled
953953
allEvents.push(newTaskFailedEvent(1, new Error("Failure on attempt 1")));
954954
allEvents.push(newTimerCreatedEvent(2, timerFireAt!));
955955
executor = new OrchestrationExecutor(registry);
956-
actions = await executor.execute(TEST_INSTANCE_ID, allEvents, [
956+
result = await executor.execute(TEST_INSTANCE_ID, allEvents, [
957957
newTimerFiredEvent(2, timerFireAt!),
958958
]);
959-
expect(actions.length).toBe(1);
960-
expect(actions[0].hasScheduletask()).toBe(true);
959+
expect(result.actions.length).toBe(1);
960+
expect(result.actions[0].hasScheduletask()).toBe(true);
961961

962962
// Step 4: Second activity attempt fails - max attempts reached
963963
allEvents.push(newTimerFiredEvent(2, timerFireAt!));
964964
allEvents.push(newTaskScheduledEvent(3, "alwaysFailsActivity"));
965965
executor = new OrchestrationExecutor(registry);
966-
actions = await executor.execute(TEST_INSTANCE_ID, allEvents, [
966+
result = await executor.execute(TEST_INSTANCE_ID, allEvents, [
967967
newTaskFailedEvent(3, new Error("Failure on attempt 2")),
968968
]);
969969

970970
// Assert: Orchestration should fail
971-
const completeAction = getAndValidateSingleCompleteOrchestrationAction(actions);
971+
const completeAction = getAndValidateSingleCompleteOrchestrationAction(result);
972972
expect(completeAction?.getOrchestrationstatus()).toEqual(pb.OrchestrationStatus.ORCHESTRATION_STATUS_FAILED);
973973
});
974974
});

0 commit comments

Comments
 (0)