2121from temporalio .common import WorkflowIDConflictPolicy
2222from temporalio .testing import WorkflowEnvironment
2323from temporalio .worker import Worker
24- from tests .helpers import print_interleaved_histories
2524from tests .helpers .nexus import create_nexus_endpoint , make_nexus_endpoint_name
2625
2726
@@ -50,10 +49,10 @@ async def run(self) -> None:
5049 try :
5150 await asyncio .Future ()
5251 except asyncio .CancelledError :
53- if (
54- test_context . cancellation_type
55- == workflow .NexusOperationCancellationType .WAIT_REQUESTED
56- ) :
52+ if test_context . cancellation_type in [
53+ workflow . NexusOperationCancellationType . TRY_CANCEL ,
54+ workflow .NexusOperationCancellationType .WAIT_REQUESTED ,
55+ ] :
5756 # We want to prove that the caller op future can be resolved before the operation
5857 # (i.e. its backing workflow) is cancelled.
5958 await self .caller_op_future_resolved .wait ()
@@ -193,10 +192,10 @@ async def run(self, input: Input) -> CancellationResult:
193192 datetime .now (timezone .utc )
194193 )
195194 assert op_handle .operation_token
196- if (
197- input . cancellation_type
198- == workflow .NexusOperationCancellationType .WAIT_REQUESTED
199- ) :
195+ if input . cancellation_type in [
196+ workflow . NexusOperationCancellationType . TRY_CANCEL ,
197+ workflow .NexusOperationCancellationType .WAIT_REQUESTED ,
198+ ] :
200199 # We want to prove that the future can be unblocked before the handler workflow is
201200 # cancelled. Send a signal, so that handler workflow can wait for it.
202201 await workflow .get_external_workflow_handle_for (
@@ -307,7 +306,6 @@ async def check_behavior_for_abandon(
307306 caller_wf ,
308307 EventType .EVENT_TYPE_NEXUS_OPERATION_CANCEL_REQUESTED ,
309308 )
310- await print_interleaved_histories ([caller_wf , handler_wf ])
311309
312310
313311async def check_behavior_for_try_cancel (
@@ -326,24 +324,16 @@ async def check_behavior_for_try_cancel(
326324 else :
327325 pytest .fail ("Expected WorkflowFailureError" )
328326 await caller_wf .signal (CallerWorkflow .release )
329- result = await caller_wf .result ()
327+ await caller_wf .result ()
330328
331329 handler_status = (await handler_wf .describe ()).status
332330 assert handler_status == WorkflowExecutionStatus .CANCELED
333331 caller_op_future_resolved = test_context .caller_op_future_resolved .result ()
334- cancel_handler_released = test_context .cancel_handler_released .result ()
335- await print_interleaved_histories (
336- [caller_wf , handler_wf ],
337- extra_events = [
338- (caller_wf , "Future unblocked" , caller_op_future_resolved ),
339- (handler_wf , "Cancel handler released" , cancel_handler_released ),
340- ],
341- )
342332 await _assert_event_subsequence (
343333 [
344- (caller_wf , EventType .EVENT_TYPE_WORKFLOW_EXECUTION_STARTED ),
345334 (caller_wf , EventType .EVENT_TYPE_NEXUS_OPERATION_CANCEL_REQUESTED ),
346335 (caller_wf , EventType .EVENT_TYPE_NEXUS_OPERATION_CANCEL_REQUEST_COMPLETED ),
336+ (caller_wf , EventType .EVENT_TYPE_NEXUS_OPERATION_CANCELED ),
347337 ]
348338 )
349339 op_cancel_requested_event = await _get_event_time (
@@ -385,10 +375,9 @@ async def check_behavior_for_wait_cancellation_requested(
385375 assert handler_status == WorkflowExecutionStatus .CANCELED
386376 await _assert_event_subsequence (
387377 [
388- (caller_wf , EventType .EVENT_TYPE_WORKFLOW_EXECUTION_STARTED ),
389378 (caller_wf , EventType .EVENT_TYPE_NEXUS_OPERATION_CANCEL_REQUESTED ),
379+ (caller_wf , EventType .EVENT_TYPE_NEXUS_OPERATION_CANCEL_REQUEST_COMPLETED ),
390380 (caller_wf , EventType .EVENT_TYPE_NEXUS_OPERATION_CANCELED ),
391- (caller_wf , EventType .EVENT_TYPE_WORKFLOW_EXECUTION_COMPLETED ),
392381 ]
393382 )
394383 caller_op_future_resolved = test_context .caller_op_future_resolved .result ()
@@ -400,12 +389,6 @@ async def check_behavior_for_wait_cancellation_requested(
400389 handler_wf ,
401390 EventType .EVENT_TYPE_WORKFLOW_EXECUTION_CANCELED ,
402391 )
403- await print_interleaved_histories (
404- [caller_wf , handler_wf ],
405- extra_events = [
406- (caller_wf , "Future unblocked" , caller_op_future_resolved ),
407- ],
408- )
409392 assert op_cancel_request_completed < caller_op_future_resolved < op_canceled
410393
411394
@@ -417,7 +400,6 @@ async def check_behavior_for_wait_cancellation_completed(
417400 Check that a cancellation request is sent and the caller workflow nexus operation future is
418401 unblocked after the operation is canceled.
419402 """
420- # For WAIT_COMPLETED, wait for the handler workflow to complete
421403 try :
422404 await handler_wf .result ()
423405 except WorkflowFailureError as err :
@@ -429,7 +411,7 @@ async def check_behavior_for_wait_cancellation_completed(
429411 assert handler_status == WorkflowExecutionStatus .CANCELED
430412
431413 await caller_wf .signal (CallerWorkflow .release )
432- result = await caller_wf .result ()
414+ await caller_wf .result ()
433415
434416 await _assert_event_subsequence (
435417 [
@@ -449,15 +431,7 @@ async def check_behavior_for_wait_cancellation_completed(
449431 handler_wf ,
450432 EventType .EVENT_TYPE_WORKFLOW_EXECUTION_CANCELED ,
451433 )
452- await print_interleaved_histories (
453- [caller_wf , handler_wf ],
454- extra_events = [
455- (caller_wf , "Future unblocked" , caller_op_future_resolved ),
456- ],
457- )
458- assert (
459- caller_op_future_resolved > handler_wf_canceled_event_time
460- ), "For WAIT_COMPLETED, the future should be unblocked after handler workflow cancellation. "
434+ assert caller_op_future_resolved > handler_wf_canceled_event_time
461435
462436
463437async def _has_event (wf_handle : WorkflowHandle , event_type : EventType .ValueType ):
0 commit comments