@@ -26,7 +26,11 @@ async def via_create_task():
26
26
await asyncio .Future ()
27
27
raise RuntimeError ("Unreachable" )
28
28
except asyncio .CancelledError :
29
- activity .heartbeat ("cancelled" )
29
+ cancellation_details = activity .cancellation_details ()
30
+ if cancellation_details :
31
+ activity .heartbeat (
32
+ f"cancelled={ cancellation_details .cancel_requested } " ,
33
+ )
30
34
return "done"
31
35
32
36
env = ActivityEnvironment ()
@@ -37,9 +41,11 @@ async def via_create_task():
37
41
task = asyncio .create_task (env .run (do_stuff , "param1" ))
38
42
await waiting .wait ()
39
43
# Cancel and confirm done
40
- env .cancel ()
44
+ env .cancel (
45
+ cancellation_details = activity .ActivityCancellationDetails (cancel_requested = True )
46
+ )
41
47
assert "done" == await task
42
- assert heartbeats == ["param: param1" , "task, type: unknown" , "cancelled" ]
48
+ assert heartbeats == ["param: param1" , "task, type: unknown" , "cancelled=True " ]
43
49
44
50
45
51
def test_activity_env_sync ():
@@ -72,7 +78,11 @@ def via_thread():
72
78
raise RuntimeError ("Unexpected" )
73
79
except CancelledError :
74
80
nonlocal properly_cancelled
75
- properly_cancelled = True
81
+ cancellation_details = activity .cancellation_details ()
82
+ if cancellation_details :
83
+ properly_cancelled = cancellation_details .cancel_requested
84
+ else :
85
+ properly_cancelled = False
76
86
77
87
env = ActivityEnvironment ()
78
88
# Set heartbeat handler to add to list
@@ -84,7 +94,9 @@ def via_thread():
84
94
waiting .wait ()
85
95
# Cancel and confirm done
86
96
time .sleep (1 )
87
- env .cancel ()
97
+ env .cancel (
98
+ cancellation_details = activity .ActivityCancellationDetails (cancel_requested = True )
99
+ )
88
100
thread .join ()
89
101
assert heartbeats == ["param: param1" , "task, type: unknown" ]
90
102
assert properly_cancelled
0 commit comments