clean up tests w/ default protocols in place

This commit is contained in:
Alex Stokes 2019-11-06 15:04:17 -08:00
parent ed81562a89
commit e61a5a677f
No known key found for this signature in database
GPG Key ID: 51CE1721B245C086
2 changed files with 4 additions and 22 deletions

View File

@ -11,4 +11,6 @@ def test_default_protocols():
mux = host.get_mux() mux = host.get_mux()
handlers = mux.handlers handlers = mux.handlers
assert handlers == get_default_protocols(host) # NOTE: comparing keys for equality as handlers may be closures that do not compare in the way
# this test is concerned with
assert handlers.keys() == get_default_protocols(host).keys()

View File

@ -3,28 +3,16 @@ import secrets
import pytest import pytest
from libp2p.host.ping import ID, PING_LENGTH, handle_ping from libp2p.host.ping import ID, PING_LENGTH
from libp2p.peer.peerinfo import info_from_p2p_addr from libp2p.peer.peerinfo import info_from_p2p_addr
from tests.utils import set_up_nodes_by_transport_opt from tests.utils import set_up_nodes_by_transport_opt
def _add_ping_to(host):
host.set_stream_handler(ID, handle_ping)
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_ping_once(): async def test_ping_once():
transport_opt_list = [["/ip4/127.0.0.1/tcp/0"], ["/ip4/127.0.0.1/tcp/0"]] transport_opt_list = [["/ip4/127.0.0.1/tcp/0"], ["/ip4/127.0.0.1/tcp/0"]]
(host_a, host_b) = await set_up_nodes_by_transport_opt(transport_opt_list) (host_a, host_b) = await set_up_nodes_by_transport_opt(transport_opt_list)
# NOTE: this will fail after we add ping as a default handler
# as a forced reminder to fix this test by removing the calls to
# `_add_ping_to`
assert host_a.get_mux().handlers == {}
assert host_b.get_mux().handlers == {}
_add_ping_to(host_a)
_add_ping_to(host_b)
addr = host_a.get_addrs()[0] addr = host_a.get_addrs()[0]
info = info_from_p2p_addr(addr) info = info_from_p2p_addr(addr)
await host_b.connect(info) await host_b.connect(info)
@ -45,14 +33,6 @@ async def test_ping_several():
transport_opt_list = [["/ip4/127.0.0.1/tcp/0"], ["/ip4/127.0.0.1/tcp/0"]] transport_opt_list = [["/ip4/127.0.0.1/tcp/0"], ["/ip4/127.0.0.1/tcp/0"]]
(host_a, host_b) = await set_up_nodes_by_transport_opt(transport_opt_list) (host_a, host_b) = await set_up_nodes_by_transport_opt(transport_opt_list)
# NOTE: this will fail after we add ping as a default handler
# as a forced reminder to fix this test by removing the calls to
# `_add_ping_to`
assert host_a.get_mux().handlers == {}
assert host_b.get_mux().handlers == {}
_add_ping_to(host_a)
_add_ping_to(host_b)
addr = host_a.get_addrs()[0] addr = host_a.get_addrs()[0]
info = info_from_p2p_addr(addr) info = info_from_p2p_addr(addr)
await host_b.connect(info) await host_b.connect(info)