2019-09-17 23:38:11 +08:00
|
|
|
import pytest
|
2019-12-01 17:43:14 +08:00
|
|
|
import trio
|
2019-12-17 15:50:55 +08:00
|
|
|
from trio.testing import wait_all_tasks_blocked
|
2019-09-17 23:38:11 +08:00
|
|
|
|
|
|
|
|
2019-12-01 16:51:06 +08:00
|
|
|
@pytest.mark.trio
|
2019-09-17 23:38:11 +08:00
|
|
|
async def test_swarm_conn_close(swarm_conn_pair):
|
|
|
|
conn_0, conn_1 = swarm_conn_pair
|
|
|
|
|
2019-12-17 15:50:55 +08:00
|
|
|
assert not conn_0.is_closed
|
|
|
|
assert not conn_1.is_closed
|
2019-09-17 23:38:11 +08:00
|
|
|
|
|
|
|
await conn_0.close()
|
|
|
|
|
2019-12-17 15:50:55 +08:00
|
|
|
await trio.sleep(0.1)
|
|
|
|
await wait_all_tasks_blocked()
|
|
|
|
await conn_0.manager.wait_finished()
|
2019-09-17 23:38:11 +08:00
|
|
|
|
2019-12-17 15:50:55 +08:00
|
|
|
assert conn_0.is_closed
|
|
|
|
assert conn_1.is_closed
|
2019-09-17 23:38:11 +08:00
|
|
|
assert conn_0 not in conn_0.swarm.connections.values()
|
|
|
|
assert conn_1 not in conn_1.swarm.connections.values()
|
|
|
|
|
|
|
|
|
2019-12-01 16:51:06 +08:00
|
|
|
@pytest.mark.trio
|
2019-09-17 23:38:11 +08:00
|
|
|
async def test_swarm_conn_streams(swarm_conn_pair):
|
|
|
|
conn_0, conn_1 = swarm_conn_pair
|
|
|
|
|
|
|
|
assert len(await conn_0.get_streams()) == 0
|
|
|
|
assert len(await conn_1.get_streams()) == 0
|
|
|
|
|
|
|
|
stream_0_0 = await conn_0.new_stream()
|
2019-12-01 16:51:06 +08:00
|
|
|
await trio.sleep(0.01)
|
2019-09-17 23:38:11 +08:00
|
|
|
assert len(await conn_0.get_streams()) == 1
|
|
|
|
assert len(await conn_1.get_streams()) == 1
|
|
|
|
|
|
|
|
stream_0_1 = await conn_0.new_stream()
|
2019-12-01 16:51:06 +08:00
|
|
|
await trio.sleep(0.01)
|
2019-09-17 23:38:11 +08:00
|
|
|
assert len(await conn_0.get_streams()) == 2
|
|
|
|
assert len(await conn_1.get_streams()) == 2
|
|
|
|
|
|
|
|
conn_0.remove_stream(stream_0_0)
|
|
|
|
assert len(await conn_0.get_streams()) == 1
|
|
|
|
conn_0.remove_stream(stream_0_1)
|
|
|
|
assert len(await conn_0.get_streams()) == 0
|
2019-09-18 15:44:45 +08:00
|
|
|
# Nothing happen if `stream_0_1` is not present or already removed.
|
|
|
|
conn_0.remove_stream(stream_0_1)
|