Remove cleanup
`cleanup` cancels all tasks in the loop, including the main one run by `run_until_complete`
This commit is contained in:
parent
a45eb76421
commit
bb0da41eda
@ -4,7 +4,7 @@ import pytest
|
||||
|
||||
from libp2p.peer.peerinfo import info_from_p2p_addr
|
||||
from libp2p.protocol_muxer.exceptions import MultiselectClientError
|
||||
from tests.utils import cleanup, set_up_nodes_by_transport_opt
|
||||
from tests.utils import set_up_nodes_by_transport_opt
|
||||
|
||||
PROTOCOL_ID = "/chat/1.0.0"
|
||||
|
||||
@ -101,5 +101,3 @@ async def test_chat(test):
|
||||
await host_b.connect(info)
|
||||
|
||||
await test(host_a, host_b)
|
||||
|
||||
await cleanup()
|
||||
|
@ -3,7 +3,7 @@ import pytest
|
||||
|
||||
from libp2p.peer.peerinfo import info_from_p2p_addr
|
||||
from tests.constants import MAX_READ_LEN
|
||||
from tests.utils import cleanup, set_up_nodes_by_transport_opt
|
||||
from tests.utils import set_up_nodes_by_transport_opt
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@ -34,7 +34,6 @@ async def test_simple_messages():
|
||||
assert response == ("ack:" + message)
|
||||
|
||||
# Success, terminate pending tasks.
|
||||
await cleanup()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@ -69,7 +68,6 @@ async def test_double_response():
|
||||
assert response2 == ("ack2:" + message)
|
||||
|
||||
# Success, terminate pending tasks.
|
||||
await cleanup()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@ -120,7 +118,6 @@ async def test_multiple_streams():
|
||||
)
|
||||
|
||||
# Success, terminate pending tasks.
|
||||
await cleanup()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@ -183,7 +180,6 @@ async def test_multiple_streams_same_initiator_different_protocols():
|
||||
)
|
||||
|
||||
# Success, terminate pending tasks.
|
||||
await cleanup()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@ -264,7 +260,6 @@ async def test_multiple_streams_two_initiators():
|
||||
)
|
||||
|
||||
# Success, terminate pending tasks.
|
||||
await cleanup()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@ -326,7 +321,6 @@ async def test_triangle_nodes_connection():
|
||||
assert response == ("ack:" + message)
|
||||
|
||||
# Success, terminate pending tasks.
|
||||
await cleanup()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@ -353,4 +347,3 @@ async def test_host_connect():
|
||||
assert addr.encapsulate(ma_node_b) in node_b.get_addrs()
|
||||
|
||||
# Success, terminate pending tasks.
|
||||
await cleanup()
|
||||
|
@ -17,7 +17,7 @@ from libp2p.crypto.rsa import create_new_key_pair
|
||||
from libp2p.host.basic_host import BasicHost
|
||||
from libp2p.network.notifee_interface import INotifee
|
||||
from tests.constants import MAX_READ_LEN
|
||||
from tests.utils import cleanup, perform_two_host_set_up
|
||||
from tests.utils import perform_two_host_set_up
|
||||
|
||||
ACK = "ack:"
|
||||
|
||||
@ -91,7 +91,6 @@ async def test_one_notifier():
|
||||
assert response == expected_resp
|
||||
|
||||
# Success, terminate pending tasks.
|
||||
await cleanup()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@ -138,7 +137,6 @@ async def test_one_notifier_on_two_nodes():
|
||||
assert response == expected_resp
|
||||
|
||||
# Success, terminate pending tasks.
|
||||
await cleanup()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@ -203,7 +201,6 @@ async def test_one_notifier_on_two_nodes_with_listen():
|
||||
assert response == expected_resp
|
||||
|
||||
# Success, terminate pending tasks.
|
||||
await cleanup()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@ -235,7 +232,6 @@ async def test_two_notifiers():
|
||||
assert response == expected_resp
|
||||
|
||||
# Success, terminate pending tasks.
|
||||
await cleanup()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@ -271,7 +267,6 @@ async def test_ten_notifiers():
|
||||
assert response == expected_resp
|
||||
|
||||
# Success, terminate pending tasks.
|
||||
await cleanup()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@ -325,7 +320,6 @@ async def test_ten_notifiers_on_two_nodes():
|
||||
assert response == expected_resp
|
||||
|
||||
# Success, terminate pending tasks.
|
||||
await cleanup()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@ -355,4 +349,3 @@ async def test_invalid_notifee():
|
||||
assert response == expected_resp
|
||||
|
||||
# Success, terminate pending tasks.
|
||||
await cleanup()
|
||||
|
@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
|
||||
from libp2p.protocol_muxer.exceptions import MultiselectClientError
|
||||
from tests.utils import cleanup, echo_stream_handler, set_up_nodes_by_transport_opt
|
||||
from tests.utils import echo_stream_handler, set_up_nodes_by_transport_opt
|
||||
|
||||
# TODO: Add tests for multiple streams being opened on different
|
||||
# protocols through the same connection
|
||||
@ -35,7 +35,6 @@ async def perform_simple_test(
|
||||
assert expected_selected_protocol == stream.get_protocol()
|
||||
|
||||
# Success, terminate pending tasks.
|
||||
await cleanup()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@ -52,7 +51,6 @@ async def test_single_protocol_fails():
|
||||
await perform_simple_test("", ["/echo/1.0.0"], ["/potato/1.0.0"])
|
||||
|
||||
# Cleanup not reached on error
|
||||
await cleanup()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@ -83,4 +81,3 @@ async def test_multiple_protocol_fails():
|
||||
await perform_simple_test("", protocols_for_client, protocols_for_listener)
|
||||
|
||||
# Cleanup not reached on error
|
||||
await cleanup()
|
||||
|
@ -4,7 +4,7 @@ import pytest
|
||||
|
||||
from tests.configs import LISTEN_MADDR
|
||||
from tests.factories import PubsubFactory
|
||||
from tests.utils import cleanup, connect
|
||||
from tests.utils import connect
|
||||
|
||||
from .configs import FLOODSUB_PROTOCOL_ID
|
||||
|
||||
@ -258,4 +258,3 @@ async def perform_test_from_obj(obj, router_factory):
|
||||
assert node_map[origin_node_id].get_id().to_bytes() == msg.from_id
|
||||
|
||||
# Success, terminate pending tasks.
|
||||
await cleanup()
|
||||
|
@ -3,7 +3,7 @@ from threading import Thread
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.utils import cleanup, connect
|
||||
from tests.utils import connect
|
||||
|
||||
from .dummy_account_node import DummyAccountNode
|
||||
|
||||
@ -64,7 +64,6 @@ async def perform_test(num_nodes, adjacency_map, action_func, assertion_func):
|
||||
assertion_func(dummy_node)
|
||||
|
||||
# Success, terminate pending tasks.
|
||||
await cleanup()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
@ -4,7 +4,7 @@ import pytest
|
||||
|
||||
from libp2p.peer.id import ID
|
||||
from tests.factories import FloodsubFactory
|
||||
from tests.utils import cleanup, connect
|
||||
from tests.utils import connect
|
||||
|
||||
from .floodsub_integration_test_settings import (
|
||||
floodsub_protocol_pytest_params,
|
||||
@ -36,7 +36,6 @@ async def test_simple_two_nodes(pubsubs_fsub):
|
||||
assert res_b.topicIDs == [topic]
|
||||
|
||||
# Success, terminate pending tasks.
|
||||
await cleanup()
|
||||
|
||||
|
||||
# Initialize Pubsub with a cache_size of 4
|
||||
@ -82,7 +81,6 @@ async def test_lru_cache_two_nodes(pubsubs_fsub, monkeypatch):
|
||||
assert sub_b.empty()
|
||||
|
||||
# Success, terminate pending tasks.
|
||||
await cleanup()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_case_obj", floodsub_protocol_pytest_params)
|
||||
|
@ -3,7 +3,7 @@ import random
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.utils import cleanup, connect
|
||||
from tests.utils import connect
|
||||
|
||||
from .configs import GossipsubParams
|
||||
from .utils import dense_connect, one_to_all_connect
|
||||
@ -61,8 +61,6 @@ async def test_join(num_hosts, hosts, pubsubs_gsub):
|
||||
assert hosts[i].get_id() not in gossipsubs[central_node_index].mesh[topic]
|
||||
assert topic not in gossipsubs[i].mesh
|
||||
|
||||
await cleanup()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("num_hosts", (1,))
|
||||
@pytest.mark.asyncio
|
||||
@ -81,8 +79,6 @@ async def test_leave(pubsubs_gsub):
|
||||
# Test re-leave
|
||||
await gossipsub.leave(topic)
|
||||
|
||||
await cleanup()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("num_hosts", (2,))
|
||||
@pytest.mark.asyncio
|
||||
@ -133,8 +129,6 @@ async def test_handle_graft(pubsubs_gsub, hosts, event_loop, monkeypatch):
|
||||
# Check that bob is now alice's mesh peer
|
||||
assert id_bob in gossipsubs[index_alice].mesh[topic]
|
||||
|
||||
await cleanup()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"num_hosts, gossipsub_params", ((2, GossipsubParams(heartbeat_interval=3)),)
|
||||
@ -174,8 +168,6 @@ async def test_handle_prune(pubsubs_gsub, hosts):
|
||||
assert id_alice not in gossipsubs[index_bob].mesh[topic]
|
||||
assert id_bob in gossipsubs[index_alice].mesh[topic]
|
||||
|
||||
await cleanup()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("num_hosts", (10,))
|
||||
@pytest.mark.asyncio
|
||||
@ -210,7 +202,6 @@ async def test_dense(num_hosts, pubsubs_gsub, hosts):
|
||||
for queue in queues:
|
||||
msg = await queue.get()
|
||||
assert msg.data == msg_content
|
||||
await cleanup()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("num_hosts", (10,))
|
||||
@ -268,8 +259,6 @@ async def test_fanout(hosts, pubsubs_gsub):
|
||||
msg = await queue.get()
|
||||
assert msg.data == msg_content
|
||||
|
||||
await cleanup()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("num_hosts", (10,))
|
||||
@pytest.mark.asyncio
|
||||
@ -340,8 +329,6 @@ async def test_fanout_maintenance(hosts, pubsubs_gsub):
|
||||
msg = await queue.get()
|
||||
assert msg.data == msg_content
|
||||
|
||||
await cleanup()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"num_hosts, gossipsub_params",
|
||||
@ -380,5 +367,3 @@ async def test_gossip_propagation(hosts, pubsubs_gsub):
|
||||
# should be able to read message
|
||||
msg = await queue_1.get()
|
||||
assert msg.data == msg_content
|
||||
|
||||
await cleanup()
|
||||
|
@ -6,7 +6,7 @@ from libp2p import new_node
|
||||
from libp2p.crypto.rsa import create_new_key_pair
|
||||
from libp2p.security.insecure.transport import InsecureSession, InsecureTransport
|
||||
from tests.configs import LISTEN_MADDR
|
||||
from tests.utils import cleanup, connect
|
||||
from tests.utils import connect
|
||||
|
||||
# TODO: Add tests for multiple streams being opened on different
|
||||
# protocols through the same connection
|
||||
@ -57,7 +57,6 @@ async def perform_simple_test(
|
||||
assertion_func(node2_conn.secured_conn)
|
||||
|
||||
# Success, terminate pending tasks.
|
||||
await cleanup()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
@ -1,6 +1,3 @@
|
||||
import asyncio
|
||||
from contextlib import suppress
|
||||
|
||||
import multiaddr
|
||||
|
||||
from libp2p import new_node
|
||||
@ -17,20 +14,6 @@ async def connect(node1, node2):
|
||||
await node1.connect(info)
|
||||
|
||||
|
||||
# FIXME: Should be deprecated, since it also kills the main task.
|
||||
async def cleanup():
|
||||
pending = asyncio.all_tasks()
|
||||
for task in pending:
|
||||
task.cancel()
|
||||
|
||||
# Now we should await task to execute it's cancellation.
|
||||
# Cancelled task raises asyncio.CancelledError that we can suppress:
|
||||
# NOTE: Changed from `asyncio.CancelledError` to `Exception`, to suppress all exceptions
|
||||
# including the one in `run_until_complete`.
|
||||
with suppress(Exception):
|
||||
await task
|
||||
|
||||
|
||||
async def set_up_nodes_by_transport_opt(transport_opt_list):
|
||||
nodes_list = []
|
||||
for transport_opt in transport_opt_list:
|
||||
|
Loading…
x
Reference in New Issue
Block a user