I have a workflow that starts a child workflow and abandons it. In my unit tests, I want to test them both, but since the child workflow starts with .start
it doesn’t support automatic time-skipping and waits for sleep commands. How can I enable time-skipping for the child workflow?
workflows.ts
const childWorkflow = async () => {
...some logic...
// waits in the tests
await sleep(15000);
...some logic...
};
const parentWorkflow = async () => {
...some logic...
// doesn't wait in tests
await sleep(10000);
...some logic...
const child = await startChild(childWorkflow.name, {
args: ['arg1'],
parentClosePolicy: ParentClosePolicy.PARENT_CLOSE_POLICY_ABANDON,
cancellationType: ChildWorkflowCancellationType.ABANDON,
});
return {
providerWorkflowDetails: {id: child.workflowId, runId: child.firstExecutionRunId}
}
};
workflows.test.ts
const execute = async (): Promise<void> => {
const worker = await Worker.create({
connection: testEnv.nativeConnection,
taskQueue: 'test',
workflowsPath: require.resolve('./workflows.ts'),
activities,
});
return await worker.runUntil(async (): Promise<void> => {
const response = await testEnv.client.workflow.execute(parentWorkflow.name, {
workflowId: uuidv4(),
taskQueue: 'test',
});
if (response?.providerWorkflowDetails) {
const providerWorkflow = testEnv.client.workflow.getHandle(
response.providerWorkflowDetails.id,
response.providerWorkflowDetails.runId,
);
await providerWorkflow.result();
}
});
};