mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 16:10:57 +00:00
added ping_service tests
This commit is contained in:
committed by
Paul Robinson
parent
25b35dee1a
commit
1ab689a1e2
@ -6,6 +6,7 @@ import trio
|
|||||||
from libp2p.host.ping import (
|
from libp2p.host.ping import (
|
||||||
ID,
|
ID,
|
||||||
PING_LENGTH,
|
PING_LENGTH,
|
||||||
|
PingService,
|
||||||
)
|
)
|
||||||
from libp2p.tools.factories import (
|
from libp2p.tools.factories import (
|
||||||
host_pair_factory,
|
host_pair_factory,
|
||||||
@ -47,3 +48,28 @@ async def test_ping_several(security_protocol):
|
|||||||
# NOTE: this interval can be `0` for this test.
|
# NOTE: this interval can be `0` for this test.
|
||||||
await trio.sleep(0)
|
await trio.sleep(0)
|
||||||
await stream.close()
|
await stream.close()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.trio
|
||||||
|
async def test_ping_service_once(security_protocol):
|
||||||
|
async with host_pair_factory(security_protocol=security_protocol) as (
|
||||||
|
host_a,
|
||||||
|
host_b,
|
||||||
|
):
|
||||||
|
ping_service = PingService(host_b)
|
||||||
|
rtts = await ping_service.ping(host_a.get_id())
|
||||||
|
assert len(rtts) == 1
|
||||||
|
assert rtts[0] < 10**6
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.trio
|
||||||
|
async def test_ping_service_several(security_protocol):
|
||||||
|
async with host_pair_factory(security_protocol=security_protocol) as (
|
||||||
|
host_a,
|
||||||
|
host_b,
|
||||||
|
):
|
||||||
|
ping_service = PingService(host_b)
|
||||||
|
rtts = await ping_service.ping(host_a.get_id(), ping_amt=SOME_PING_COUNT)
|
||||||
|
assert len(rtts) == SOME_PING_COUNT
|
||||||
|
for rtt in rtts:
|
||||||
|
assert rtt < 10**6
|
||||||
|
|||||||
Reference in New Issue
Block a user