Skip to content

Commit ba1bfbb

Browse files
committed
Cleanup
1 parent fcd40ef commit ba1bfbb

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

tests/test_serialization_context.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -520,12 +520,7 @@ async def test_async_activity_completion_payload_conversion(
520520
await activity_handle.complete(data)
521521
result = await wf_handle.result()
522522

523-
# project down since activity completion by a client does not have access to most activity
524-
# context fields
525-
def project(trace_item: TraceItem) -> str:
526-
return trace_item.method
527-
528-
assert [project(item) for item in result.items] == [
523+
assert [item.method for item in result.items] == [
529524
"to_payload", # Outbound activity input
530525
"to_payload", # Outbound activity heartbeat data
531526
"from_payload", # Inbound activity result
@@ -1528,15 +1523,14 @@ def with_context(
15281523
codec.context = context
15291524
return codec
15301525

1531-
async def encode(self, payloads: Sequence[Payload]) -> List[Payload]:
1526+
async def _assert_context_iff_not_nexus(
1527+
self, payloads: Sequence[Payload]
1528+
) -> List[Payload]:
15321529
[payload] = payloads
15331530
assert bool(self.context) == (payload.data.decode() != '"nexus-data"')
15341531
return list(payloads)
15351532

1536-
async def decode(self, payloads: Sequence[Payload]) -> List[Payload]:
1537-
[payload] = payloads
1538-
assert bool(self.context) == (payload.data.decode() != '"nexus-data"')
1539-
return list(payloads)
1533+
encode = decode = _assert_context_iff_not_nexus
15401534

15411535

15421536
@nexusrpc.handler.service_handler
@@ -1567,9 +1561,6 @@ async def test_nexus_payload_codec_operations_lack_context(
15671561
"""
15681562
encode() and decode() on nexus payloads should not have any context set.
15691563
"""
1570-
workflow_id = str(uuid.uuid4())
1571-
task_queue = str(uuid.uuid4())
1572-
15731564
config = client.config()
15741565
config["data_converter"] = dataclasses.replace(
15751566
DataConverter.default,
@@ -1579,16 +1570,16 @@ async def test_nexus_payload_codec_operations_lack_context(
15791570

15801571
async with Worker(
15811572
client,
1582-
task_queue=task_queue,
1573+
task_queue=str(uuid.uuid4()),
15831574
workflows=[NexusOperationTestWorkflow],
15841575
nexus_service_handlers=[NexusOperationTestServiceHandler()],
1585-
):
1586-
await create_nexus_endpoint(task_queue, client)
1576+
) as worker:
1577+
await create_nexus_endpoint(worker.task_queue, client)
15871578
await client.execute_workflow(
15881579
NexusOperationTestWorkflow.run,
15891580
"workflow-data",
1590-
id=workflow_id,
1591-
task_queue=task_queue,
1581+
id=str(uuid.uuid4()),
1582+
task_queue=worker.task_queue,
15921583
)
15931584

15941585

0 commit comments

Comments
 (0)