Add cases for send()

This commit is contained in:
boukeversteegh 2020-06-15 18:14:13 +02:00
parent f7aa6150e2
commit 0814729c5a

View File

@ -13,20 +13,13 @@ class Message(betterproto.Message):
body: str = betterproto.string_field(1)
async def to_list(generator: AsyncIterator):
lis = []
async for value in generator:
lis.append(value)
return lis
@pytest.fixture
def expected_responses():
return [Message("Hello world 1"), Message("Hello world 2"), Message("Done")]
class ClientStub:
async def connect(self, requests):
async def connect(self, requests: AsyncIterator):
await asyncio.sleep(0.1)
async for request in requests:
await asyncio.sleep(0.1)
@ -35,6 +28,13 @@ class ClientStub:
yield Message("Done")
async def to_list(generator: AsyncIterator):
lis = []
async for value in generator:
lis.append(value)
return lis
@pytest.fixture
def client():
# channel = Channel(host='127.0.0.1', port=50051)
@ -122,3 +122,30 @@ async def test_send_from_close_manually_immediately(client, expected_responses):
requests.close()
assert await to_list(responses) == expected_responses
@pytest.mark.asyncio
async def test_send_individually_and_close_before_connect(client, expected_responses):
requests = AsyncChannel()
await requests.send(Message(body="Hello world 1"))
await requests.send(Message(body="Hello world 2"))
requests.close()
responses = client.connect(requests)
assert await to_list(responses) == expected_responses
@pytest.mark.asyncio
async def test_send_individually_and_close_after_connect(client, expected_responses):
requests = AsyncChannel()
await requests.send(Message(body="Hello world 1"))
await requests.send(Message(body="Hello world 2"))
responses = client.connect(requests)
requests.close()
assert await to_list(responses) == expected_responses