Skip to content

Commit d82e489

Browse files
committed
Fix sync client testing
1 parent b333c1d commit d82e489

1 file changed

Lines changed: 7 additions & 12 deletions

File tree

tests/test_sync_client.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
import asyncio
22
import threading
3-
import time
4-
from asyncio import Event
53
from collections.abc import AsyncIterator
64

75
import grpc
86
import pytest
97
from grpclib.server import Server
108

11-
from tests.output_betterproto.simple_service import (
12-
Request,
13-
Response,
14-
SimpleServiceBase,
15-
SimpleServiceSyncStub,
16-
)
9+
from tests.output_betterproto.simple_service import Request, Response, SimpleServiceBase, SimpleServiceSyncStub
1710

1811

1912
class SimpleService(SimpleServiceBase):
@@ -37,13 +30,15 @@ async def get_stream_stream(self, messages: "AsyncIterator[Request]") -> "AsyncI
3730

3831
@pytest.mark.asyncio
3932
async def test_sync_client():
40-
# The event will be set to close the server
41-
close_server_event = Event() # TODO the event is used in two different asyncio loops
33+
start_server_event = threading.Event()
34+
close_server_event = asyncio.Event()
4235

4336
def start_server():
4437
async def run_server():
4538
server = Server([SimpleService()])
4639
await server.start("127.0.0.1", 1234)
40+
start_server_event.set()
41+
4742
await close_server_event.wait()
4843
server.close()
4944

@@ -56,9 +51,9 @@ async def run_server():
5651
server_thread.start()
5752

5853
# Create a sync client
59-
with grpc.insecure_channel("localhost:1234") as channel:
60-
time.sleep(1) # TODO not a good solution
54+
start_server_event.wait()
6155

56+
with grpc.insecure_channel("localhost:1234") as channel:
6257
client = SimpleServiceSyncStub(channel)
6358

6459
response = client.get_unary_unary(Request(value=42))

0 commit comments

Comments
 (0)