|
5 | 5 | import uuid |
6 | 6 | from dataclasses import dataclass, field |
7 | 7 | from datetime import timedelta |
| 8 | +from itertools import zip_longest |
8 | 9 | from pprint import pprint |
9 | 10 | from typing import Any, Literal, Optional, Type |
10 | 11 |
|
@@ -186,37 +187,86 @@ async def test_workflow_payload_conversion_can_be_given_access_to_serialization_ |
186 | 187 | namespace="default", |
187 | 188 | workflow_id=workflow_id, |
188 | 189 | ) |
189 | | - if False: |
190 | | - assert result.items == [ |
191 | | - TraceItem( |
192 | | - context_type="workflow", |
193 | | - in_workflow=False, |
194 | | - method="to_payload", |
195 | | - context=workflow_context, |
196 | | - ), |
197 | | - TraceItem( |
198 | | - context_type="workflow", |
199 | | - in_workflow=False, |
200 | | - method="from_payload", |
201 | | - context=workflow_context, |
202 | | - ), |
203 | | - TraceItem( |
204 | | - context_type="workflow", |
205 | | - in_workflow=True, |
206 | | - method="to_payload", |
207 | | - context=workflow_context, |
208 | | - ), |
209 | | - TraceItem( |
210 | | - context_type="workflow", |
211 | | - in_workflow=False, |
212 | | - method="from_payload", |
213 | | - context=workflow_context, |
214 | | - ), |
215 | | - ] |
| 190 | + activity_context = ActivitySerializationContext( |
| 191 | + namespace="default", |
| 192 | + workflow_id=workflow_id, |
| 193 | + workflow_type="SerializationContextTestWorkflow", |
| 194 | + activity_type="passthrough_activity", |
| 195 | + activity_task_queue=task_queue, |
| 196 | + is_local=False, |
| 197 | + ) |
| 198 | + if True: |
| 199 | + assert_trace( |
| 200 | + result.items, |
| 201 | + [ |
| 202 | + TraceItem( |
| 203 | + context_type="workflow", |
| 204 | + in_workflow=False, |
| 205 | + method="to_payload", |
| 206 | + context=workflow_context, |
| 207 | + ), |
| 208 | + TraceItem( |
| 209 | + context_type="workflow", |
| 210 | + in_workflow=False, |
| 211 | + method="from_payload", |
| 212 | + context=workflow_context, |
| 213 | + ), |
| 214 | + TraceItem( |
| 215 | + context_type="activity", |
| 216 | + in_workflow=True, |
| 217 | + method="to_payload", |
| 218 | + context=activity_context, |
| 219 | + ), |
| 220 | + TraceItem( |
| 221 | + context_type="activity", |
| 222 | + in_workflow=False, |
| 223 | + method="from_payload", |
| 224 | + context=activity_context, |
| 225 | + ), |
| 226 | + TraceItem( |
| 227 | + context_type="activity", |
| 228 | + in_workflow=False, |
| 229 | + method="to_payload", |
| 230 | + context=activity_context, |
| 231 | + ), |
| 232 | + TraceItem( |
| 233 | + context_type="workflow", |
| 234 | + in_workflow=False, |
| 235 | + method="from_payload", |
| 236 | + context=workflow_context, |
| 237 | + ), |
| 238 | + TraceItem( |
| 239 | + context_type="workflow", |
| 240 | + in_workflow=True, |
| 241 | + method="to_payload", |
| 242 | + context=workflow_context, |
| 243 | + ), |
| 244 | + TraceItem( |
| 245 | + context_type="workflow", |
| 246 | + in_workflow=False, |
| 247 | + method="from_payload", |
| 248 | + context=workflow_context, |
| 249 | + ), |
| 250 | + ], |
| 251 | + ) |
216 | 252 | else: |
217 | 253 | pprint(result.items) |
218 | 254 |
|
219 | 255 |
|
| 256 | +def assert_trace(trace: list[TraceItem], expected: list[TraceItem]): |
| 257 | + history = [] |
| 258 | + for item, expected_item in zip_longest(trace, expected): |
| 259 | + if item is None: |
| 260 | + raise AssertionError("Fewer items in trace than expected") |
| 261 | + if expected_item is None: |
| 262 | + raise AssertionError("More items in trace than expected") |
| 263 | + if item != expected_item: |
| 264 | + raise AssertionError( |
| 265 | + f"Item {item}\n\ndoes not match expected:\n\n {expected_item}.\n\n History:\n{'\n'.join(history)}" |
| 266 | + ) |
| 267 | + history.append(f"{item.context_type} {item.method}") |
| 268 | + |
| 269 | + |
220 | 270 | def get_caller_location() -> list[str]: |
221 | 271 | """Get 3 stack frames starting from the first that's not in test_serialization_context.py or temporalio/converter.py.""" |
222 | 272 | frame = inspect.currentframe() |
|
0 commit comments