Refactor test setup to remove duplicate code
This commit is contained in:
parent
91b4d66d50
commit
b340b89819
|
@ -45,8 +45,7 @@ class MyNotifee(INotifee):
|
||||||
async def listen_close(self, network, multiaddr):
|
async def listen_close(self, network, multiaddr):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
async def perform_two_host_simple_set_up():
|
||||||
async def test_one_notifier():
|
|
||||||
node_a = await new_node(transport_opt=["/ip4/127.0.0.1/tcp/0"])
|
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"])
|
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())
|
# 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.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
|
# Add notifee for node_a
|
||||||
events = []
|
events = []
|
||||||
|
@ -87,20 +91,7 @@ async def test_one_notifier():
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_two_notifiers():
|
async def test_two_notifiers():
|
||||||
node_a = await new_node(transport_opt=["/ip4/127.0.0.1/tcp/0"])
|
node_a, node_b = await perform_two_host_simple_set_up()
|
||||||
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)
|
|
||||||
|
|
||||||
# Add notifee for node_a
|
# Add notifee for node_a
|
||||||
events0 = []
|
events0 = []
|
||||||
|
@ -133,20 +124,7 @@ async def test_two_notifiers():
|
||||||
async def test_ten_notifiers():
|
async def test_ten_notifiers():
|
||||||
num_notifiers = 10
|
num_notifiers = 10
|
||||||
|
|
||||||
node_a = await new_node(transport_opt=["/ip4/127.0.0.1/tcp/0"])
|
node_a, node_b = await perform_two_host_simple_set_up()
|
||||||
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)
|
|
||||||
|
|
||||||
# Add notifee for node_a
|
# Add notifee for node_a
|
||||||
events_lst = []
|
events_lst = []
|
||||||
|
|
Loading…
Reference in New Issue
Block a user