|
| 1 | +import asyncio |
| 2 | +import importlib |
1 | 3 | import shutil |
2 | 4 | from datetime import timedelta |
3 | 5 |
|
| 6 | +import grpc |
| 7 | +import grpc.aio |
4 | 8 | import pytest |
5 | 9 |
|
6 | | -import importlib |
7 | 10 | from replit_river.client import Client |
8 | 11 | from replit_river.codegen.client import schema_to_river_client_codegen |
| 12 | +from replit_river.error_schema import RiverException |
| 13 | +from replit_river.rpc import rpc_method_handler |
9 | 14 | from tests.common_handlers import basic_rpc_method |
| 15 | +from tests.conftest import HandlerMapping, deserialize_request, serialize_response |
10 | 16 |
|
11 | 17 |
|
12 | 18 | @pytest.fixture(scope="session", autouse=True) |
@@ -35,3 +41,32 @@ async def test_basic_rpc(client: Client) -> None: |
35 | 41 | timedelta(seconds=5), |
36 | 42 | ) |
37 | 43 | assert res.data == "Hello, feep!", f"Expected 'Hello, feep!' received {res.data}" |
| 44 | + |
| 45 | + |
| 46 | +async def rpc_timeout_handler(request: str, context: grpc.aio.ServicerContext) -> str: |
| 47 | + await asyncio.sleep(1) |
| 48 | + return f"Hello, {request}!" |
| 49 | + |
| 50 | + |
| 51 | +rpc_timeout_method: HandlerMapping = { |
| 52 | + ("test_service", "rpc_method"): ( |
| 53 | + "rpc", |
| 54 | + rpc_method_handler( |
| 55 | + rpc_timeout_handler, deserialize_request, serialize_response |
| 56 | + ), |
| 57 | + ) |
| 58 | +} |
| 59 | + |
| 60 | + |
| 61 | +@pytest.mark.asyncio |
| 62 | +@pytest.mark.parametrize("handlers", [{**rpc_timeout_method}]) |
| 63 | +async def test_rpc_timeout(client: Client) -> None: |
| 64 | + from tests.codegen.rpc.generated import RpcClient |
| 65 | + |
| 66 | + with pytest.raises(RiverException): |
| 67 | + await RpcClient(client).test_service.rpc_method( |
| 68 | + { |
| 69 | + "data": "feep", |
| 70 | + }, |
| 71 | + timedelta(milliseconds=200), |
| 72 | + ) |
0 commit comments