mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-04-08 23:11:27 +00:00
Refactor interop tests and factories
- Add `close` and `disconnect` in `Host` - Add `close` and `close_peer` in `Network` - Change `IListener.close` to async, to await for server's closing - Add factories for security transports, and modify `HostFactory`
This commit is contained in:
33
tests/conftest.py
Normal file
33
tests/conftest.py
Normal file
@ -0,0 +1,33 @@
|
||||
import asyncio
|
||||
|
||||
import pytest
|
||||
|
||||
from .configs import LISTEN_MADDR
|
||||
from .factories import HostFactory
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def is_host_secure():
|
||||
return False
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def num_hosts():
|
||||
return 3
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def hosts(num_hosts, is_host_secure):
|
||||
_hosts = HostFactory.create_batch(num_hosts, is_secure=is_host_secure)
|
||||
await asyncio.gather(
|
||||
*[_host.get_network().listen(LISTEN_MADDR) for _host in _hosts]
|
||||
)
|
||||
try:
|
||||
yield _hosts
|
||||
finally:
|
||||
# TODO: It's possible that `close` raises exceptions currently,
|
||||
# due to the connection reset things. Though we are not so careful about that when
|
||||
# cleaning up the tasks, it is probably better to handle the exceptions properly.
|
||||
await asyncio.gather(
|
||||
*[_host.close() for _host in _hosts], return_exceptions=True
|
||||
)
|
||||
Reference in New Issue
Block a user