2019-09-13 15:29:24 +08:00
|
|
|
import asyncio
|
|
|
|
|
2019-09-02 17:32:15 +08:00
|
|
|
import pytest
|
|
|
|
|
2019-09-02 18:40:12 +08:00
|
|
|
from .utils import connect
|
|
|
|
|
2019-09-02 17:32:15 +08:00
|
|
|
|
|
|
|
@pytest.mark.parametrize("num_hosts", (1,))
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_connect(hosts, p2pds):
|
|
|
|
p2pd = p2pds[0]
|
|
|
|
host = hosts[0]
|
|
|
|
assert len(await p2pd.control.list_peers()) == 0
|
|
|
|
# Test: connect from Py
|
2019-09-02 18:40:12 +08:00
|
|
|
await connect(host, p2pd)
|
2019-09-02 17:32:15 +08:00
|
|
|
assert len(await p2pd.control.list_peers()) == 1
|
|
|
|
# Test: `disconnect` from Py
|
|
|
|
await host.disconnect(p2pd.peer_id)
|
|
|
|
assert len(await p2pd.control.list_peers()) == 0
|
|
|
|
# Test: connect from Go
|
2019-09-02 18:40:12 +08:00
|
|
|
await connect(p2pd, host)
|
2019-09-02 17:32:15 +08:00
|
|
|
assert len(host.get_network().connections) == 1
|
|
|
|
# Test: `disconnect` from Go
|
2019-09-02 18:40:12 +08:00
|
|
|
await p2pd.control.disconnect(host.get_id())
|
2019-09-13 15:29:24 +08:00
|
|
|
await asyncio.sleep(0.01)
|
|
|
|
assert len(host.get_network().connections) == 0
|