@@ -175,6 +175,15 @@ async def run(self, input: Input) -> CancellationResult:
175175 # closed as cancelled) before sending an activation job to Python resolving the
176176 # nexus operation as cancelled
177177 op_handle .cancel ()
178+ if (
179+ test_context .cancellation_type
180+ == workflow .NexusOperationCancellationType .WAIT_REQUESTED
181+ ):
182+ # For WAIT_REQUESTED, we need core to receive the NexusOperationCancelRequestCompleted
183+ # event. That event should trigger a workflow task, but does not currently due to
184+ # https://github.com/temporalio/temporal/issues/8175. Force a new WFT, allowing time for
185+ # the event hopefully to arrive.
186+ await workflow .sleep (0.1 , summary = "Force new WFT" )
178187 try :
179188 await op_handle
180189 except exceptions .NexusOperationError :
@@ -184,17 +193,22 @@ async def run(self, input: Input) -> CancellationResult:
184193 assert op_handle .operation_token
185194 # Block the thread for a bit to avoid flakiness in asserting that the future is
186195 # unblocked before the WFT completion is sent in the TryCancel case.
187- time .sleep (1e-2 )
188-
189- # Notify handler workflow that caller op future has been resolved
190- await workflow .get_external_workflow_handle_for (
191- HandlerWorkflow .run ,
192- workflow_id = (
193- nexus .WorkflowHandle [None ]
194- .from_token (self .operation_token )
195- .workflow_id
196- ),
197- ).signal (HandlerWorkflow .set_caller_op_future_resolved )
196+ time .sleep (0.01 )
197+
198+ if (
199+ input .cancellation_type
200+ == workflow .NexusOperationCancellationType .WAIT_REQUESTED
201+ ):
202+ # We want to prove that the future can be unblocked before the handler workflow is
203+ # cancelled. Send a signal, so that handler workflow can wait for it.
204+ await workflow .get_external_workflow_handle_for (
205+ HandlerWorkflow .run ,
206+ workflow_id = (
207+ nexus .WorkflowHandle [None ]
208+ .from_token (self .operation_token )
209+ .workflow_id
210+ ),
211+ ).signal (HandlerWorkflow .set_caller_op_future_resolved )
198212
199213 await workflow .wait_condition (lambda : self .released )
200214 return CancellationResult (
0 commit comments