RequestCancelExternalWorkflow Sample
I was trying to figure out the best way to test cancellations of Child Workflows. In the past, only cancelling the context was possible so I thought I'd try out RequestCancelExternalWorkflow.
I stumbled on some seeming inconsistencies I thought I'd highlight to verify whether a bug exists or not.
There are two tests:
-
Test_Cancel_NoMockywhich does not mock out ChildWorkflow execution. TheSetOnChildWorkflowCanceledListeneris invoked. It is noteworthy that usingOnRequestCancelExternalWorkflowfails, which I suppose makes sense but we should make clearer in docs that this API is only for mocked ChildWorkflow calls. -
Test_Cancel_WithMockymocks theMyChildworkflow. TheSetOnChildWorkflowCanceledListeneris not invoked, though theSetOnChildWorkflowCompletedListeneris invoked. This seems inconsistent to me. I ack that when someone usesOnRequestCancelExternalWorkflowthey should Assert the expected call on that...however since tests evolve in projects and mocking is eventually introduced for children so the cancel listener no longer being called is hard to understand. We should at least call out that the listener is not called when using this API.
This sample shows how to use the RequestCancelExternalWorkflow API.
There are some nuances using this not very obvious (to me):
- I observed that workflow tasks would fail with
Unhandled Commanderrors (appear in workflow history) when the ChildWorkflow future was not resolved. Doing a simple.Getafter callingRequestCancelExternalWorkflowExecutionfixed this. - Testing when using this API was not as straightforward as I'd hoped (see above).
- I found a bug when using
OnWorkflowmock for workflows that do not have arguments...you must still pass in an argument (egmock.Anything) or else theworkflowInterceptorpanics...seems like we are missing a check for params before spreading them somewhere.