Skip to content

Commit 4d7ddda

Browse files
committed
Test heartbeating
1 parent b2d12f4 commit 4d7ddda

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

temporalio/worker/_activity.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ async def _heartbeat_async(
252252
if details is None:
253253
return
254254

255+
assert len(details) == 1
256+
print(f"🌈 Heartbeat: details(id={id(details[0])})={details[0]}")
257+
255258
data_converter = self._data_converter
256259
if activity.info:
257260
context = temporalio.converter.ActivitySerializationContext(

tests/test_serialization_context.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import asyncio
34
import dataclasses
45
import inspect
56
import uuid
@@ -52,18 +53,23 @@ class TraceData:
5253

5354
@activity.defn
5455
async def passthrough_activity(input: TraceData) -> TraceData:
56+
activity.heartbeat(input)
57+
# Wait for the heartbeat to be processed so that it modifies the data before the activity returns
58+
await asyncio.sleep(0.2)
5559
return input
5660

5761

5862
@workflow.defn(sandboxed=False) # we want to use isinstance
5963
class SerializationContextTestWorkflow:
6064
@workflow.run
61-
async def run(self, input: TraceData) -> TraceData:
62-
return await workflow.execute_activity(
65+
async def run(self, data: TraceData) -> TraceData:
66+
data = await workflow.execute_activity(
6367
passthrough_activity,
64-
input,
68+
data,
6569
start_to_close_timeout=timedelta(seconds=10),
70+
heartbeat_timeout=timedelta(seconds=2),
6671
)
72+
return data
6773

6874

6975
class SerializationContextTestEncodingPayloadConverter(
@@ -207,49 +213,55 @@ async def test_workflow_payload_conversion_can_be_given_access_to_serialization_
207213
context_type="workflow",
208214
in_workflow=False,
209215
method="to_payload",
210-
context=workflow_context,
216+
context=workflow_context, # Outbound workflow input
211217
),
212218
TraceItem(
213219
context_type="workflow",
214220
in_workflow=False,
215221
method="from_payload",
216-
context=workflow_context,
222+
context=workflow_context, # Inbound workflow input
217223
),
218224
TraceItem(
219225
context_type="activity",
220226
in_workflow=True,
221227
method="to_payload",
222-
context=activity_context,
228+
context=activity_context, # Outbound activity input
223229
),
224230
TraceItem(
225231
context_type="activity",
226232
in_workflow=False,
227233
method="from_payload",
228-
context=activity_context,
234+
context=activity_context, # Inbound activity input
229235
),
230236
TraceItem(
231237
context_type="activity",
232238
in_workflow=False,
233239
method="to_payload",
234-
context=activity_context,
240+
context=activity_context, # Outbound heartbeat
241+
),
242+
TraceItem(
243+
context_type="activity",
244+
in_workflow=False,
245+
method="to_payload",
246+
context=activity_context, # Outbound activity result
235247
),
236248
TraceItem(
237249
context_type="activity",
238250
in_workflow=False,
239251
method="from_payload",
240-
context=activity_context,
252+
context=activity_context, # Inbound activity result
241253
),
242254
TraceItem(
243255
context_type="workflow",
244256
in_workflow=True,
245257
method="to_payload",
246-
context=workflow_context,
258+
context=workflow_context, # Outbound workflow result
247259
),
248260
TraceItem(
249261
context_type="workflow",
250262
in_workflow=False,
251263
method="from_payload",
252-
context=workflow_context,
264+
context=workflow_context, # Inbound workflow result
253265
),
254266
],
255267
)

0 commit comments

Comments
 (0)