Skip to content

Commit d13b483

Browse files
authored
fix(workflow): Don't propagate cancellation from non-cancellable scopes to children (backport from #1429) (#1466)
1 parent 3b6daa7 commit d13b483

23 files changed

+928
-192
lines changed

packages/test/src/helpers-integration.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,18 @@ export interface Helpers {
9898
assertWorkflowFailedError(p: Promise<any>, causeConstructor: ErrorConstructor, message?: string): Promise<void>;
9999
}
100100

101-
export function helpers(t: ExecutionContext<Context>): Helpers {
101+
export function helpers(t: ExecutionContext<Context>, testEnv: TestWorkflowEnvironment = t.context.env): Helpers {
102102
const taskQueue = t.title.replace(/ /g, '_');
103103

104104
return {
105105
taskQueue,
106106
async createWorker(opts?: Partial<WorkerOptions>): Promise<Worker> {
107107
return await Worker.create({
108-
connection: t.context.env.nativeConnection,
108+
connection: testEnv.nativeConnection,
109109
workflowBundle: t.context.workflowBundle,
110110
taskQueue,
111111
interceptors: {
112-
activity: [() => ({ inbound: new ConnectionInjectorInterceptor(t.context.env.connection) })],
112+
activity: [() => ({ inbound: new ConnectionInjectorInterceptor(testEnv.connection) })],
113113
},
114114
showStackTraceSources: true,
115115
...opts,
@@ -119,7 +119,7 @@ export function helpers(t: ExecutionContext<Context>): Helpers {
119119
fn: workflow.Workflow,
120120
opts?: Omit<WorkflowStartOptions, 'taskQueue' | 'workflowId'>
121121
): Promise<any> {
122-
return await t.context.env.client.workflow.execute(fn, {
122+
return await testEnv.client.workflow.execute(fn, {
123123
taskQueue,
124124
workflowId: randomUUID(),
125125
...opts,
@@ -129,7 +129,7 @@ export function helpers(t: ExecutionContext<Context>): Helpers {
129129
fn: workflow.Workflow,
130130
opts?: Omit<WorkflowStartOptions, 'taskQueue' | 'workflowId'>
131131
): Promise<WorkflowHandle<workflow.Workflow>> {
132-
return await t.context.env.client.workflow.start(fn, {
132+
return await testEnv.client.workflow.start(fn, {
133133
taskQueue,
134134
workflowId: randomUUID(),
135135
...opts,

packages/test/src/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export function cleanStackTrace(ostack: string): string {
7272
return normalizedStack ? `${firstLine}\n${normalizedStack}` : firstLine;
7373
}
7474

75-
function noopTest() {
75+
function noopTest(): void {
7676
// eslint: this function body is empty and it's okay.
7777
}
7878

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { getActivator } from '@temporalio/workflow/lib/global-attributes';
2+
import { SdkFlag } from '@temporalio/workflow/lib/flags';
3+
4+
const defaultValueOverrides = new Map<number, boolean>();
5+
6+
let mockInstalled = false;
7+
8+
function maybeInstallMock() {
9+
if (mockInstalled) return;
10+
const activator = getActivator();
11+
const originalHasFlag = activator.hasFlag.bind(activator);
12+
activator.hasFlag = (flag) => {
13+
const overridenDefaultValue = defaultValueOverrides.get(flag.id);
14+
if (overridenDefaultValue !== undefined) {
15+
flag = { id: flag.id, default: overridenDefaultValue };
16+
}
17+
return originalHasFlag(flag);
18+
};
19+
mockInstalled = true;
20+
}
21+
22+
// Override the default value of an SDK flag. That is, assuming a workflow execution is not in
23+
// replay mode and that `f` has not already been recorded, then `hasFlag(f)` will return
24+
// `defaultValue`, and record the flag to history if `defaultValue` is `true`.
25+
export function overrideSdkInternalFlag(flag: SdkFlag, defaultValue: boolean): void {
26+
maybeInstallMock();
27+
defaultValueOverrides.set(flag.id, defaultValue);
28+
}

0 commit comments

Comments
 (0)