Skip to content

Commit 9a690dc

Browse files
authored
test: Test ABNADONED child timer can be fast-forwarded (#772)
1 parent 31c8cc2 commit 9a690dc

File tree

3 files changed

+44
-10
lines changed

3 files changed

+44
-10
lines changed

packages/test/src/test-testenvironment.ts

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import { v4 as uuid4 } from 'uuid';
33
import { WorkflowFailedError } from '@temporalio/client';
44
import { TestWorkflowEnvironment, workflowInterceptorModules } from '@temporalio/testing';
55
import { Connection } from '@temporalio/testing/lib/connection';
6+
import { bundleWorkflowCode, WorkflowBundleWithSourceMap } from '@temporalio/worker';
67
import {
78
assertFromWorkflow,
9+
asyncChildStarter,
810
raceActivityAndTimer,
911
sleep,
1012
unblockSignal,
@@ -14,13 +16,18 @@ import { Worker } from './helpers';
1416

1517
interface Context {
1618
testEnv: TestWorkflowEnvironment;
19+
bundle: WorkflowBundleWithSourceMap;
1720
}
1821

1922
const test = anyTest as TestFn<Context>;
2023

2124
test.before(async (t) => {
2225
t.context = {
2326
testEnv: await TestWorkflowEnvironment.createTimeSkipping(),
27+
bundle: await bundleWorkflowCode({
28+
workflowsPath: require.resolve('./workflows/testenv-test-workflows'),
29+
workflowInterceptorModules,
30+
}),
2431
};
2532
});
2633

@@ -33,7 +40,7 @@ test.serial('TestEnvironment sets up test server and is able to run a Workflow w
3340
const worker = await Worker.create({
3441
connection: nativeConnection,
3542
taskQueue: 'test',
36-
workflowsPath: require.resolve('./workflows/testenv-test-workflows'),
43+
workflowBundle: t.context.bundle,
3744
});
3845
await worker.runUntil(
3946
client.workflow.execute(sleep, {
@@ -51,7 +58,7 @@ test.serial('TestEnvironment can toggle between normal and skipped time', async
5158
const worker = await Worker.create({
5259
connection: nativeConnection,
5360
taskQueue: 'test',
54-
workflowsPath: require.resolve('./workflows/testenv-test-workflows'),
61+
workflowBundle: t.context.bundle,
5562
});
5663

5764
await worker.runUntil(async () => {
@@ -87,7 +94,7 @@ test.serial('TestEnvironment sleep can be used to delay activity completion', as
8794
await sleep(duration);
8895
},
8996
},
90-
workflowsPath: require.resolve('./workflows/testenv-test-workflows'),
97+
workflowBundle: t.context.bundle,
9198
});
9299

93100
const run = async (expectedWinner: 'timer' | 'activity') => {
@@ -123,7 +130,7 @@ test.serial('TestEnvironment sleep can be used to delay sending a signal', async
123130
const worker = await Worker.create({
124131
connection: nativeConnection,
125132
taskQueue: 'test',
126-
workflowsPath: require.resolve('./workflows/testenv-test-workflows'),
133+
workflowBundle: t.context.bundle,
127134
});
128135

129136
await worker.runUntil(async () => {
@@ -144,10 +151,7 @@ test.serial('Workflow code can run assertions', async (t) => {
144151
const worker = await Worker.create({
145152
connection: nativeConnection,
146153
taskQueue: 'test',
147-
workflowsPath: require.resolve('./workflows/testenv-test-workflows'),
148-
interceptors: {
149-
workflowModules: workflowInterceptorModules,
150-
},
154+
workflowBundle: t.context.bundle,
151155
});
152156

153157
const err: WorkflowFailedError | undefined = await t.throwsAsync(
@@ -162,3 +166,25 @@ test.serial('Workflow code can run assertions', async (t) => {
162166
);
163167
t.is(err?.cause?.message, 'Expected values to be strictly equal:\n\n6 !== 7\n');
164168
});
169+
170+
test.serial('ABNADONED child timer can be fast-forwarded', async (t) => {
171+
const { client, nativeConnection } = t.context.testEnv;
172+
173+
const worker = await Worker.create({
174+
connection: nativeConnection,
175+
taskQueue: 'test',
176+
workflowBundle: t.context.bundle,
177+
});
178+
179+
const childWorkflowId = uuid4();
180+
await worker.runUntil(async () => {
181+
await client.workflow.execute(asyncChildStarter, {
182+
workflowId: uuid4(),
183+
taskQueue: 'test',
184+
args: [childWorkflowId],
185+
});
186+
await client.workflow.getHandle(childWorkflowId).result();
187+
});
188+
189+
t.pass();
190+
});

packages/test/src/workflows/testenv-test-workflows.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import assert from 'assert';
7-
import { sleep, proxyActivities, defineSignal, setHandler } from '@temporalio/workflow';
7+
import { sleep, proxyActivities, defineSignal, setHandler, startChild, ParentClosePolicy } from '@temporalio/workflow';
88

99
// Export sleep to be invoked as a workflow
1010
export { sleep };
@@ -32,3 +32,11 @@ export async function waitOnSignalWithTimeout(): Promise<void> {
3232
export async function assertFromWorkflow(x: number): Promise<void> {
3333
assert.strictEqual(x, 7);
3434
}
35+
36+
export async function asyncChildStarter(childWorkflowId: string): Promise<void> {
37+
await startChild(sleep, {
38+
args: ['1 day'],
39+
workflowId: childWorkflowId,
40+
parentClosePolicy: ParentClosePolicy.PARENT_CLOSE_POLICY_ABANDON,
41+
});
42+
}

packages/testing/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
} from '@temporalio/client';
2525
import { ActivityFunction, CancelledFailure } from '@temporalio/common';
2626
import { msToTs, tsToMs } from '@temporalio/common/lib/time';
27-
import { NativeConnection, Runtime } from '@temporalio/worker';
27+
import { NativeConnection, Runtime, appendDefaultInterceptors } from '@temporalio/worker';
2828
import {
2929
EphemeralServer,
3030
EphemeralServerConfig,

0 commit comments

Comments
 (0)