Refactor test setup to remove duplicate code

This commit is contained in:
Stuckinaboot 2019-03-03 23:44:15 +11:00
parent 91b4d66d50
commit b340b89819

View File

@ -45,8 +45,7 @@ class MyNotifee(INotifee):
async def listen_close(self, network, multiaddr):
pass
@pytest.mark.asyncio
async def test_one_notifier():
async def perform_two_host_simple_set_up():
node_a = await new_node(transport_opt=["/ip4/127.0.0.1/tcp/0"])
node_b = await new_node(transport_opt=["/ip4/127.0.0.1/tcp/0"])
@ -61,6 +60,11 @@ async def test_one_notifier():
# Associate the peer with local ip address (see default parameters of Libp2p())
node_a.get_peerstore().add_addrs(node_b.get_id(), node_b.get_addrs(), 10)
return node_a, node_b
@pytest.mark.asyncio
async def test_one_notifier():
node_a, node_b = await perform_two_host_simple_set_up()
# Add notifee for node_a
events = []
@ -87,20 +91,7 @@ async def test_one_notifier():
@pytest.mark.asyncio
async def test_two_notifiers():
node_a = await new_node(transport_opt=["/ip4/127.0.0.1/tcp/0"])
node_b = await new_node(transport_opt=["/ip4/127.0.0.1/tcp/0"])
async def stream_handler(stream):
while True:
read_string = (await stream.read()).decode()
response = "ack:" + read_string
await stream.write(response.encode())
node_b.set_stream_handler("/echo/1.0.0", stream_handler)
# Associate the peer with local ip address (see default parameters of Libp2p())
node_a.get_peerstore().add_addrs(node_b.get_id(), node_b.get_addrs(), 10)
node_a, node_b = await perform_two_host_simple_set_up()
# Add notifee for node_a
events0 = []
@ -133,20 +124,7 @@ async def test_two_notifiers():
async def test_ten_notifiers():
num_notifiers = 10
node_a = await new_node(transport_opt=["/ip4/127.0.0.1/tcp/0"])
node_b = await new_node(transport_opt=["/ip4/127.0.0.1/tcp/0"])
async def stream_handler(stream):
while True:
read_string = (await stream.read()).decode()
response = "ack:" + read_string
await stream.write(response.encode())
node_b.set_stream_handler("/echo/1.0.0", stream_handler)
# Associate the peer with local ip address (see default parameters of Libp2p())
node_a.get_peerstore().add_addrs(node_b.get_id(), node_b.get_addrs(), 10)
node_a, node_b = await perform_two_host_simple_set_up()
# Add notifee for node_a
events_lst = []