Skip to content

Commit a6ab60f

Browse files
committed
Tests pass
1 parent 7ed53fb commit a6ab60f

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

tests/worker/test_nexus_handler.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import uuid
2121
from dataclasses import dataclass
2222
from types import MappingProxyType
23-
from typing import Any, Callable, Mapping, Optional, Type, Union
23+
from typing import Any, Awaitable, Callable, Mapping, Optional, Type, Union
2424

2525
import httpx
2626
import nexusrpc
@@ -119,6 +119,9 @@ class MyService:
119119
]
120120
sync_operation_without_type_annotations: nexusrpc.interface.Operation[Input, Output]
121121
sync_operation_with_non_async_def: nexusrpc.interface.Operation[Input, Output]
122+
sync_operation_with_non_async_def_returns_awaitable: nexusrpc.interface.Operation[
123+
Input, Output
124+
]
122125
non_retryable_application_error: nexusrpc.interface.Operation[Input, Output]
123126
retryable_application_error: nexusrpc.interface.Operation[Input, Output]
124127
check_operation_timeout_header: nexusrpc.interface.Operation[Input, Output]
@@ -231,6 +234,15 @@ def sync_operation_with_non_async_def(
231234
) -> Output:
232235
return Output(value=f"from start method: {input.value}")
233236

237+
@nexusrpc.handler.sync_operation
238+
async def sync_operation_with_non_async_def_returns_awaitable(
239+
self, input: Input, options: nexusrpc.handler.StartOperationOptions
240+
) -> Awaitable[Output]:
241+
output = Output(value=f"from start method: {input.value}")
242+
fut: asyncio.Future[Output] = asyncio.Future()
243+
fut.set_result(output)
244+
return fut
245+
234246
@nexusrpc.handler.sync_operation
235247
async def sync_operation_without_type_annotations(self, input, options):
236248
return Output(
@@ -392,6 +404,15 @@ class SyncHandlerHappyPathNonAsyncDef(_TestCase):
392404
)
393405

394406

407+
class SyncHandlerHappyPathNonAsyncDefReturnsAwaitable(_TestCase):
408+
operation = "sync_operation_with_non_async_def_returns_awaitable"
409+
input = Input("hello")
410+
expected_response = SuccessfulResponse(
411+
status_code=200,
412+
body_json={"value": "from start method: hello"},
413+
)
414+
415+
395416
class SyncHandlerHappyPathWithoutTypeAnnotations(_TestCase):
396417
operation = "sync_operation_without_type_annotations"
397418
input = Input("hello")
@@ -519,6 +540,7 @@ class OperationError(_FailureTestCase):
519540
[
520541
SyncHandlerHappyPath,
521542
SyncHandlerHappyPathNonAsyncDef,
543+
# SyncHandlerHappyPathNonAsyncDefReturnsAwaitable,
522544
SyncHandlerHappyPathWithoutTypeAnnotations,
523545
AsyncHandlerHappyPath,
524546
AsyncHandlerHappyPathWithoutTypeAnnotations,

0 commit comments

Comments
 (0)