Skip to content

Commit 5a1fe50

Browse files
committed
Test non-serializable operation output
1 parent bce0fd0 commit 5a1fe50

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/nexus/test_handler.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ class Output:
5656
value: str
5757

5858

59+
@dataclass
60+
class NonSerializableOutput:
61+
callable: Callable[[], Any] = lambda: None
62+
63+
5964
@dataclass
6065
class TestContext:
6166
workflow_id: Optional[str] = None
@@ -96,6 +101,7 @@ class MyService:
96101
handler_error_internal: nexusrpc.Operation[Input, Output]
97102
operation_error_failed: nexusrpc.Operation[Input, Output]
98103
idempotency_check: nexusrpc.Operation[None, Output]
104+
non_serializable_output: nexusrpc.Operation[Input, NonSerializableOutput]
99105

100106

101107
@workflow.defn
@@ -292,6 +298,12 @@ async def idempotency_check(
292298
) -> Output:
293299
return Output(value=f"request_id: {ctx.request_id}")
294300

301+
@nexusrpc.handler.sync_operation_handler
302+
async def non_serializable_output(
303+
self, ctx: StartOperationContext, input: Input
304+
) -> NonSerializableOutput:
305+
return NonSerializableOutput()
306+
295307

296308
@dataclass
297309
class Failure:
@@ -653,6 +665,15 @@ class UnknownOperation(_FailureTestCase):
653665
)
654666

655667

668+
class NonSerializableOutputFailure(_FailureTestCase):
669+
operation = "non_serializable_output"
670+
expected = UnsuccessfulResponse(
671+
status_code=500,
672+
retryable_header=False,
673+
failure_message="Object of type function is not JSON serializable",
674+
)
675+
676+
656677
@pytest.mark.parametrize(
657678
"test_case",
658679
[
@@ -687,6 +708,7 @@ async def test_start_operation_happy_path(
687708
HandlerErrorInternal,
688709
UnknownService,
689710
UnknownOperation,
711+
NonSerializableOutputFailure,
690712
],
691713
)
692714
async def test_start_operation_protocol_level_failures(

0 commit comments

Comments
 (0)