I’m trying to test my workflow which listens to 2 signals before it is able to complete:
export const completeModelingProcessSignal = workflow.defineSignal<
[
| CompleteModelingProcessForDenseReconstructionUseCaseDTO
| CompleteModelingProcessForSFMUseCaseDTO
]
>('completeModelingProcess');
export const completePaymentForModelingProcessSignal = workflow.defineSignal<
[CompletePaymentForModelingProcessUseCaseDTO]
>('completePaymentForModelingProcess');
export async function modelingProcessWorkflow(
modelingProcessId: string
): Promise<any> {
let paymentCompleted = false;
const {
startModelingProcess,
completeModelingProcess,
completePaymentForModelingProcess
} = workflow.proxyActivities<typeof activities>({
startToCloseTimeout: '540 minutes'
});
const startModelingProcessResult = await startModelingProcess({
modelingProcessId
});
workflow.setHandler(
completeModelingProcessSignal,
async (
dto:
| CompleteModelingProcessForDenseReconstructionUseCaseDTO
| CompleteModelingProcessForSFMUseCaseDTO
) => {
console.log('completeModelingProcessSignal');
await completeModelingProcess(dto);
}
);
workflow.setHandler(
completePaymentForModelingProcessSignal,
async (dto: CompletePaymentForModelingProcessUseCaseDTO) => {
await completePaymentForModelingProcess(dto);
paymentCompleted = true;
}
);
await workflow.condition(() => paymentCompleted === true, '180 minutes');
return startModelingProcessResult;
}
I have currently set up my test to be something like:
let testEnv: TestWorkflowEnvironment;
const workflowCoverage = new WorkflowCoverage();
describe('Create model', () => {
let nativeConnection: NativeConnection;
let temporalClient: Client;
beforeAll(async () => {
Runtime.install({
logger: new DefaultLogger('WARN', (entry: LogEntry) =>
console.log(`[${entry.level}]`, entry.message)
)
});
testEnv = await TestWorkflowEnvironment.createLocal();
nativeConnection = testEnv.nativeConnection;
temporalClient = testEnv.client;
}, 150000);
afterAll((done) => {
...
});
test('The end to end process', async () => {
let kubernetesUrl: string | undefined;
let manifestFile: any;
mockClient(S3Client);
const axiosMock = new MockAdapter(axios);
axiosMock.onPost().reply((config) => {
kubernetesUrl = config.url;
manifestFile = yaml.load(config.data.toString());
return [200, {}];
});
const worker = await Worker.create(
workflowCoverage.augmentWorkerOptions({
connection: nativeConnection,
taskQueue: 'test',
workflowsPath: require.resolve(
'../../../../../src/web/temporal/workflow'
),
activities
})
);
const startWorkflow = async () => {
await worker.runUntil(async () => {
console.log('Before calling');
const result = await temporalClient.workflow.execute(
modelingProcessWorkflow,
{
workflowId:
createModelingProcessResponse.body.data.createModelingProcessV2
.id,
taskQueue: 'test',
args: [
createModelingProcessResponse.body.data.createModelingProcessV2.id
]
}
);
console.log('After calling');
console.log(result);
});
};
...
})
Though I am struggling to figure out what is the best way to Signal the workflow. The most similar thing I’ve seen is in this discussion here but it is using the Go SDK.
I believe that I can use temporalClient.workflowService.signalWorkflowExecution
to send a signal directly with gRPC I believe this is the associated docs though I’m unable to figure out what I need to give to it to Signal my workflow.
Am I looking at the right thing, or is there a better way to Signal the workflow?