mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-09 14:40:53 +00:00
Do p2pd.close if not all of them succeed
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import asyncio
|
||||
import sys
|
||||
from typing import Union
|
||||
|
||||
import pexpect
|
||||
import pytest
|
||||
@ -7,7 +8,7 @@ import pytest
|
||||
from tests.factories import FloodsubFactory, GossipsubFactory, PubsubFactory
|
||||
from tests.pubsub.configs import GOSSIPSUB_PARAMS
|
||||
|
||||
from .daemon import make_p2pd
|
||||
from .daemon import Daemon, make_p2pd
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -42,7 +43,7 @@ def is_gossipsub():
|
||||
|
||||
@pytest.fixture
|
||||
async def p2pds(num_p2pds, is_host_secure, is_gossipsub, unused_tcp_port_factory):
|
||||
p2pds = await asyncio.gather(
|
||||
p2pds: Union[Daemon, Exception] = await asyncio.gather(
|
||||
*[
|
||||
make_p2pd(
|
||||
unused_tcp_port_factory(),
|
||||
@ -51,8 +52,15 @@ async def p2pds(num_p2pds, is_host_secure, is_gossipsub, unused_tcp_port_factory
|
||||
is_gossipsub=is_gossipsub,
|
||||
)
|
||||
for _ in range(num_p2pds)
|
||||
]
|
||||
],
|
||||
return_exceptions=True,
|
||||
)
|
||||
p2pds_succeeded = tuple(p2pd for p2pd in p2pds if isinstance(p2pd, Daemon))
|
||||
if len(p2pds_succeeded) != len(p2pds):
|
||||
# Not all succeeded. Close the succeeded ones and print the failed ones(exceptions).
|
||||
await asyncio.gather(*[p2pd.close() for p2pd in p2pds_succeeded])
|
||||
exceptions = tuple(p2pd for p2pd in p2pds if isinstance(p2pd, Exception))
|
||||
raise Exception(f"not all p2pds succeed: first exception={exceptions[0]}")
|
||||
try:
|
||||
yield p2pds
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user