Skip to content

Commit e142407

Browse files
authored
chore: Add test for module property mutation isolation (#1356)
1 parent 1394965 commit e142407

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

packages/test/src/test-isolation.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,45 @@ test('Global state is isolated and maintained between activations', async (t) =>
6464
});
6565
});
6666

67-
export async function propertyMutator(): Promise<void> {
67+
export async function sdkPropertyMutator(): Promise<void> {
6868
try {
6969
(arrayFromPayloads as any).a = 1;
7070
} catch (err) {
7171
throw ApplicationFailure.fromError(err);
7272
}
7373
}
7474

75-
test('Module state is frozen', withReusableContext, async (t) => {
75+
test('SDK Module state is frozen', withReusableContext, async (t) => {
7676
const { createWorker, taskQueue, env } = t.context;
7777
const worker = await createWorker();
7878
const err = (await worker.runUntil(
79-
t.throwsAsync(env.client.workflow.execute(propertyMutator, { taskQueue, workflowId: randomUUID() }))
79+
t.throwsAsync(env.client.workflow.execute(sdkPropertyMutator, { taskQueue, workflowId: randomUUID() }))
8080
)) as WorkflowFailedError;
8181
t.is(err.cause?.message, 'Cannot add property a, object is not extensible');
8282
});
8383

84+
const someArr: number[] = [];
85+
86+
export async function modulePropertyMutator(): Promise<number[]> {
87+
someArr.push(1);
88+
await sleep(1);
89+
someArr.push(2);
90+
return someArr;
91+
}
92+
93+
test('Module state is isolated and maintained between activations', async (t) => {
94+
const { createWorker, taskQueue, env } = t.context;
95+
const worker = await createWorker();
96+
await worker.runUntil(async () => {
97+
const [res1, res2] = await Promise.all([
98+
env.client.workflow.execute(modulePropertyMutator, { taskQueue, workflowId: randomUUID() }),
99+
env.client.workflow.execute(modulePropertyMutator, { taskQueue, workflowId: randomUUID() }),
100+
]);
101+
t.deepEqual(res1, [1, 2]);
102+
t.deepEqual(res2, [1, 2]);
103+
});
104+
});
105+
84106
export async function sharedGlobalMutator(): Promise<void> {
85107
try {
86108
(setTimeout as any).a = 1;

0 commit comments

Comments
 (0)