Skip to content

Commit

Permalink
fix(workflow): Don't propagate cancellation from non-cancellable scop…
Browse files Browse the repository at this point in the history
…es to children (backport from #1429) (#1466)
  • Loading branch information
mjameswh committed Jul 16, 2024
1 parent 3b6daa7 commit d13b483
Show file tree
Hide file tree
Showing 23 changed files with 928 additions and 192 deletions.
10 changes: 5 additions & 5 deletions packages/test/src/helpers-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,18 @@ export interface Helpers {
assertWorkflowFailedError(p: Promise<any>, causeConstructor: ErrorConstructor, message?: string): Promise<void>;
}

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

return {
taskQueue,
async createWorker(opts?: Partial<WorkerOptions>): Promise<Worker> {
return await Worker.create({
connection: t.context.env.nativeConnection,
connection: testEnv.nativeConnection,
workflowBundle: t.context.workflowBundle,
taskQueue,
interceptors: {
activity: [() => ({ inbound: new ConnectionInjectorInterceptor(t.context.env.connection) })],
activity: [() => ({ inbound: new ConnectionInjectorInterceptor(testEnv.connection) })],
},
showStackTraceSources: true,
...opts,
Expand All @@ -119,7 +119,7 @@ export function helpers(t: ExecutionContext<Context>): Helpers {
fn: workflow.Workflow,
opts?: Omit<WorkflowStartOptions, 'taskQueue' | 'workflowId'>
): Promise<any> {
return await t.context.env.client.workflow.execute(fn, {
return await testEnv.client.workflow.execute(fn, {
taskQueue,
workflowId: randomUUID(),
...opts,
Expand All @@ -129,7 +129,7 @@ export function helpers(t: ExecutionContext<Context>): Helpers {
fn: workflow.Workflow,
opts?: Omit<WorkflowStartOptions, 'taskQueue' | 'workflowId'>
): Promise<WorkflowHandle<workflow.Workflow>> {
return await t.context.env.client.workflow.start(fn, {
return await testEnv.client.workflow.start(fn, {
taskQueue,
workflowId: randomUUID(),
...opts,
Expand Down
2 changes: 1 addition & 1 deletion packages/test/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function cleanStackTrace(ostack: string): string {
return normalizedStack ? `${firstLine}\n${normalizedStack}` : firstLine;
}

function noopTest() {
function noopTest(): void {
// eslint: this function body is empty and it's okay.
}

Expand Down
28 changes: 28 additions & 0 deletions packages/test/src/mock-internal-flags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { getActivator } from '@temporalio/workflow/lib/global-attributes';
import { SdkFlag } from '@temporalio/workflow/lib/flags';

const defaultValueOverrides = new Map<number, boolean>();

let mockInstalled = false;

function maybeInstallMock() {
if (mockInstalled) return;
const activator = getActivator();
const originalHasFlag = activator.hasFlag.bind(activator);
activator.hasFlag = (flag) => {
const overridenDefaultValue = defaultValueOverrides.get(flag.id);
if (overridenDefaultValue !== undefined) {
flag = { id: flag.id, default: overridenDefaultValue };
}
return originalHasFlag(flag);
};
mockInstalled = true;
}

// Override the default value of an SDK flag. That is, assuming a workflow execution is not in
// replay mode and that `f` has not already been recorded, then `hasFlag(f)` will return
// `defaultValue`, and record the flag to history if `defaultValue` is `true`.
export function overrideSdkInternalFlag(flag: SdkFlag, defaultValue: boolean): void {
maybeInstallMock();
defaultValueOverrides.set(flag.id, defaultValue);
}
Loading

0 comments on commit d13b483

Please # to comment.