Skip to content

Commit e18638d

Browse files
committed
added test, fixed broken test
1 parent 58ba7d5 commit e18638d

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

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

+53-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { activityStartedSignal } from './workflows/definitions';
2424
import * as workflows from './workflows';
2525
import { Context, createLocalTestEnvironment, helpers, makeTestFunction } from './helpers-integration';
2626
import { overrideSdkInternalFlag } from './mock-internal-flags';
27-
import { asSdkLoggerSink, loadHistory, RUN_TIME_SKIPPING_TESTS } from './helpers';
27+
import { asSdkLoggerSink, loadHistory, RUN_TIME_SKIPPING_TESTS, waitUntil } from './helpers';
2828

2929
const test = makeTestFunction({
3030
workflowsPath: __filename,
@@ -1337,3 +1337,55 @@ test('can register search attributes to dev server', async (t) => {
13371337
t.deepEqual(desc.searchAttributes, { 'new-search-attr': [12] }); // eslint-disable-line deprecation/deprecation
13381338
await env.teardown();
13391339
});
1340+
1341+
export async function ChildWorkflowInfo(): Promise<workflow.RootWorkflowInfo | undefined> {
1342+
let blocked = true;
1343+
workflow.setHandler(unblockSignal, () => {
1344+
blocked = false;
1345+
});
1346+
await workflow.condition(() => !blocked);
1347+
return workflow.workflowInfo().root;
1348+
}
1349+
1350+
export async function WithChildWorkflow(childWfId: string) {
1351+
return await workflow.executeChild(ChildWorkflowInfo, {
1352+
workflowId: childWfId,
1353+
});
1354+
}
1355+
1356+
test('root execution is exposed', async (t) => {
1357+
const { createWorker, startWorkflow } = helpers(t);
1358+
const worker = await createWorker();
1359+
1360+
await worker.runUntil(async () => {
1361+
const childWfId = 'child-wf-id';
1362+
const handle = await startWorkflow(WithChildWorkflow, {
1363+
args: [childWfId],
1364+
});
1365+
1366+
const childHandle = t.context.env.client.workflow.getHandle(childWfId);
1367+
const childStarted = async (): Promise<boolean> => {
1368+
try {
1369+
await childHandle.describe();
1370+
return true;
1371+
} catch (e) {
1372+
if (e instanceof workflow.WorkflowNotFoundError) {
1373+
return false;
1374+
} else {
1375+
throw e;
1376+
}
1377+
}
1378+
};
1379+
await waitUntil(childStarted, 3000);
1380+
const childDesc = await childHandle.describe();
1381+
const parentDesc = await handle.describe();
1382+
1383+
t.true(childDesc.rootExecution?.workflowId == parentDesc.workflowId);
1384+
t.true(childDesc.rootExecution?.runId == parentDesc.runId);
1385+
1386+
await childHandle.signal(unblockSignal);
1387+
const childWfInfoRoot = await handle.result();
1388+
t.true(childWfInfoRoot?.workflowId == parentDesc.workflowId);
1389+
t.true(childWfInfoRoot?.runId == parentDesc.runId);
1390+
});
1391+
});

packages/test/src/test-sinks.ts

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ if (RUN_INTEGRATION_TESTS) {
117117
lastResult: undefined,
118118
memo: {},
119119
parent: undefined,
120+
root: undefined,
120121
searchAttributes: {},
121122
// FIXME: consider rehydrating the class before passing to sink functions or
122123
// create a variant of WorkflowInfo that corresponds to what we actually get in sinks.

0 commit comments

Comments
 (0)