Skip to content

Commit b0e6bb9

Browse files
committed
Fix integration tests.
1 parent 92f457f commit b0e6bb9

5 files changed

Lines changed: 20 additions & 12 deletions

File tree

packages/common/src/interceptors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function composeInterceptorsWith<I, M extends keyof I>(
3333
next: Next<I, M>,
3434
wrapNext: WrapNext
3535
): Next<I, M> {
36-
let composedNext: any = wrapNext(next as any);
36+
let composedNext: any = next;
3737
for (let i = interceptors.length - 1; i >= 0; --i) {
3838
const interceptor = interceptors[i];
3939
if (interceptor?.[method] !== undefined) {

packages/test/src/test-interceptors.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ if (RUN_INTEGRATION_TESTS) {
258258
ApplicationFailure: Expected anything other than 1
259259
at $CLASS.nonRetryable (common/src/failure.ts)
260260
at Object.continueAsNew (test/src/workflows/interceptor-example.ts)
261+
at composedNext (common/src/interceptors.ts)
261262
at workflow/src/workflow.ts
262263
at continueAsNewToDifferentWorkflow (test/src/workflows/continue-as-new-to-different-workflow.ts)
263264
`;

packages/workflow/src/interceptor-composition.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ import { getActivator } from './global-attributes';
2323
* explicitly establishes its own scope.
2424
*/
2525
export function composeInterceptors<I, M extends keyof I>(interceptors: I[], method: M, next: Next<I, M>): Next<I, M> {
26-
return ((input: any) => {
27-
const activator = getActivator();
28-
return (
29-
composeInterceptorsWith(interceptors, method, next, ((wrappedNext) =>
30-
activator.bindCurrentRandom(wrappedNext as any)) as <F extends (...args: any[]) => any>(next: F) => F) as any
31-
)(input);
32-
}) as unknown as Next<I, M>;
26+
const activator = getActivator();
27+
return composeInterceptorsWith(interceptors, method, next, ((wrappedNext) =>
28+
activator.bindCurrentRandom(wrappedNext as any)) as <F extends (...args: any[]) => any>(
29+
next: F
30+
) => F) as unknown as Next<I, M>;
3331
}

packages/workflow/src/internals.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,17 @@ export class Activator implements ActivationHandler {
528528
}
529529

530530
public bindCurrentRandom<T extends (...args: any[]) => any>(fn: T): T {
531-
const randomSource = this.currentRandomStorage?.getStore();
532-
return ((...args: Parameters<T>) => this.withRandomSource(randomSource, () => fn(...args))) as unknown as T;
531+
const storage = (this.currentRandomStorage ??= new AsyncLocalStorage<ScopedWorkflowRandomSource | undefined>());
532+
const randomSource = storage.getStore();
533+
const bind = (
534+
AsyncLocalStorage as typeof AsyncLocalStorage & {
535+
bind?: <F extends (...args: any[]) => any>(fn: F) => F;
536+
}
537+
).bind;
538+
if (bind) {
539+
return storage.run(randomSource, () => bind(fn)) as T;
540+
}
541+
return ((...args: Parameters<T>) => storage.run(randomSource, () => fn(...args))) as unknown as T;
533542
}
534543

535544
public currentRandom(): number {

packages/workflow/src/workflow.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ import {
6767
DefaultQueryHandler,
6868
} from './interfaces';
6969
import { LocalActivityDoBackoff } from './errors';
70-
import { currentRandom } from './current-random';
7170
import { assertInWorkflowContext, getActivator, maybeGetActivator } from './global-attributes';
7271
import { uuid4FromRandom } from './random-helpers';
7372
import { untrackPromise } from './stack-helpers';
@@ -1067,7 +1066,8 @@ export function continueAsNew<F extends Workflow>(...args: Parameters<F>): Promi
10671066
* See the {@link https://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid | stackoverflow discussion}.
10681067
*/
10691068
export function uuid4(): string {
1070-
return uuid4FromRandom(currentRandom);
1069+
const activator = maybeGetActivator();
1070+
return uuid4FromRandom(activator ? () => activator.currentRandom() : Math.random);
10711071
}
10721072

10731073
/**

0 commit comments

Comments
 (0)