diff --git a/.travis.yml b/.travis.yml index f5d470d..824fa24 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ matrix: - export GOPATH=$HOME/go - export GOROOT=/usr/local/go - export PATH=$GOROOT/bin:$GOPATH/bin:$PATH - - ./tests/interop/go_pkgs/install_interop_go_pkgs.sh + - ./tests_interop/go_pkgs/install_interop_go_pkgs.sh install: - pip install --upgrade pip diff --git a/Makefile b/Makefile index 4541270..59422bf 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -FILES_TO_LINT = libp2p tests examples setup.py +FILES_TO_LINT = libp2p tests tests_interop examples setup.py PB = libp2p/crypto/pb/crypto.proto libp2p/pubsub/pb/rpc.proto libp2p/security/insecure/pb/plaintext.proto libp2p/security/secio/pb/spipe.proto PY = $(PB:.proto=_pb2.py) PYI = $(PB:.proto=_pb2.pyi) diff --git a/setup.py b/setup.py index e3ef58e..1567c03 100644 --- a/setup.py +++ b/setup.py @@ -9,8 +9,6 @@ extras_require = { "pytest>=4.6.3,<5.0.0", "pytest-asyncio>=0.10.0,<1.0.0", "pexpect>=4.6,<5", - # FIXME: Master branch. Use PyPI instead after it is released. - "p2pclient @ git+https://git@github.com/mhchia/py-libp2p-daemon-bindings@628266f", ], "lint": [ "mypy>=0.701,<1.0", diff --git a/tests/interop/__init__.py b/tests_interop/__init__.py similarity index 100% rename from tests/interop/__init__.py rename to tests_interop/__init__.py diff --git a/tests/interop/conftest.py b/tests_interop/conftest.py similarity index 83% rename from tests/interop/conftest.py rename to tests_interop/conftest.py index c280a4c..ff4266f 100644 --- a/tests/interop/conftest.py +++ b/tests_interop/conftest.py @@ -7,13 +7,46 @@ import pexpect import pytest from libp2p.io.abc import ReadWriteCloser -from tests.factories import FloodsubFactory, GossipsubFactory, PubsubFactory +from tests.configs import LISTEN_MADDR +from tests.factories import ( + FloodsubFactory, + GossipsubFactory, + HostFactory, + PubsubFactory, +) from tests.pubsub.configs import GOSSIPSUB_PARAMS from .daemon import Daemon, make_p2pd from .utils import connect +@pytest.fixture +def is_host_secure(): + return False + + +@pytest.fixture +def num_hosts(): + return 3 + + +@pytest.fixture +async def hosts(num_hosts, is_host_secure): + _hosts = HostFactory.create_batch(num_hosts, is_secure=is_host_secure) + await asyncio.gather( + *[_host.get_network().listen(LISTEN_MADDR) for _host in _hosts] + ) + try: + yield _hosts + finally: + # TODO: It's possible that `close` raises exceptions currently, + # due to the connection reset things. Though we don't care much about that when + # cleaning up the tasks, it is probably better to handle the exceptions properly. + await asyncio.gather( + *[_host.close() for _host in _hosts], return_exceptions=True + ) + + @pytest.fixture def proc_factory(): procs = [] diff --git a/tests/interop/constants.py b/tests_interop/constants.py similarity index 100% rename from tests/interop/constants.py rename to tests_interop/constants.py diff --git a/tests/interop/daemon.py b/tests_interop/daemon.py similarity index 100% rename from tests/interop/daemon.py rename to tests_interop/daemon.py diff --git a/tests/interop/envs.py b/tests_interop/envs.py similarity index 100% rename from tests/interop/envs.py rename to tests_interop/envs.py diff --git a/tests/interop/go_pkgs/examples/README.md b/tests_interop/go_pkgs/examples/README.md similarity index 100% rename from tests/interop/go_pkgs/examples/README.md rename to tests_interop/go_pkgs/examples/README.md diff --git a/tests/interop/go_pkgs/examples/echo/main.go b/tests_interop/go_pkgs/examples/echo/main.go similarity index 100% rename from tests/interop/go_pkgs/examples/echo/main.go rename to tests_interop/go_pkgs/examples/echo/main.go diff --git a/tests/interop/go_pkgs/examples/go.mod b/tests_interop/go_pkgs/examples/go.mod similarity index 100% rename from tests/interop/go_pkgs/examples/go.mod rename to tests_interop/go_pkgs/examples/go.mod diff --git a/tests/interop/go_pkgs/examples/go.sum b/tests_interop/go_pkgs/examples/go.sum similarity index 100% rename from tests/interop/go_pkgs/examples/go.sum rename to tests_interop/go_pkgs/examples/go.sum diff --git a/tests/interop/go_pkgs/examples/utils/host.go b/tests_interop/go_pkgs/examples/utils/host.go similarity index 100% rename from tests/interop/go_pkgs/examples/utils/host.go rename to tests_interop/go_pkgs/examples/utils/host.go diff --git a/tests/interop/go_pkgs/install_interop_go_pkgs.sh b/tests_interop/go_pkgs/install_interop_go_pkgs.sh similarity index 100% rename from tests/interop/go_pkgs/install_interop_go_pkgs.sh rename to tests_interop/go_pkgs/install_interop_go_pkgs.sh diff --git a/tests/interop/test_bindings.py b/tests_interop/test_bindings.py similarity index 100% rename from tests/interop/test_bindings.py rename to tests_interop/test_bindings.py diff --git a/tests/interop/test_echo.py b/tests_interop/test_echo.py similarity index 100% rename from tests/interop/test_echo.py rename to tests_interop/test_echo.py diff --git a/tests/interop/test_net_stream.py b/tests_interop/test_net_stream.py similarity index 100% rename from tests/interop/test_net_stream.py rename to tests_interop/test_net_stream.py diff --git a/tests/interop/test_pubsub.py b/tests_interop/test_pubsub.py similarity index 100% rename from tests/interop/test_pubsub.py rename to tests_interop/test_pubsub.py diff --git a/tests/interop/utils.py b/tests_interop/utils.py similarity index 100% rename from tests/interop/utils.py rename to tests_interop/utils.py diff --git a/tox.ini b/tox.ini index 2d50b08..4d76675 100644 --- a/tox.ini +++ b/tox.ini @@ -27,11 +27,10 @@ skip_glob= [testenv] deps = -passenv = CI TRAVIS TRAVIS_* GOPATH +passenv = CI TRAVIS TRAVIS_* extras = test commands = - test: py.test --ignore=tests/interop - interop: py.test tests/interop + test: py.test tests/ -v basepython = py37: python3.7 @@ -40,6 +39,15 @@ basepython = python3 extras = dev commands = mypy -p libp2p -p examples --config-file {toxinidir}/mypy.ini - black --check libp2p tests examples setup.py - isort --recursive --check-only libp2p tests examples setup.py - flake8 libp2p tests examples setup.py + black --check libp2p tests tests_interop examples setup.py + isort --recursive --check-only libp2p tests tests_interop examples setup.py + flake8 libp2p tests tests_interop examples setup.py + +[testenv:py37-interop] +deps = p2pclient +passenv = CI TRAVIS TRAVIS_* GOPATH +extras = test +commands = + test: py.test tests_interop/ -v +basepython = + py37: python3.7