Skip to content

Commit

Permalink
Add a test for timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
blast-hardcheese committed Nov 29, 2024
1 parent 0aeaf33 commit 4c4006b
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion tests/codegen/test_rpc.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import asyncio
import importlib
import shutil
from datetime import timedelta

import grpc
import grpc.aio
import pytest

import importlib
from replit_river.client import Client
from replit_river.codegen.client import schema_to_river_client_codegen
from replit_river.error_schema import RiverException
from replit_river.rpc import rpc_method_handler
from tests.common_handlers import basic_rpc_method
from tests.conftest import HandlerMapping, deserialize_request, serialize_response


@pytest.fixture(scope="session", autouse=True)
Expand Down Expand Up @@ -35,3 +41,32 @@ async def test_basic_rpc(client: Client) -> None:
timedelta(seconds=5),
)
assert res.data == "Hello, feep!", f"Expected 'Hello, feep!' received {res.data}"


async def rpc_timeout_handler(request: str, context: grpc.aio.ServicerContext) -> str:
await asyncio.sleep(1)
return f"Hello, {request}!"


rpc_timeout_method: HandlerMapping = {
("test_service", "rpc_method"): (
"rpc",
rpc_method_handler(
rpc_timeout_handler, deserialize_request, serialize_response
),
)
}


@pytest.mark.asyncio
@pytest.mark.parametrize("handlers", [{**rpc_timeout_method}])
async def test_rpc_timeout(client: Client) -> None:
from tests.codegen.rpc.generated import RpcClient

with pytest.raises(RiverException):
await RpcClient(client).test_service.rpc_method(
{
"data": "feep",
},
timedelta(milliseconds=200),
)

0 comments on commit 4c4006b

Please sign in to comment.