Merge pull request #308 from mhchia/fix/move-deps-on-p2pclient-to-tox

Move interop tests outside `tests`
This commit is contained in:
Kevin Mai-Husan Chia 2019-09-24 13:49:35 +08:00 committed by GitHub
commit 3e9df896f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 62 additions and 16 deletions

View File

@ -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

View File

@ -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)

View File

@ -195,7 +195,11 @@ class Pubsub:
# Ref: https://developers.google.com/protocol-buffers/docs/reference/python-generated#singular-fields-proto2 # noqa: E501
if rpc_incoming.HasField("control"):
# Pass rpc to router so router could perform custom logic
logger.debug("received `control` message %s from peer %s", peer_id)
logger.debug(
"received `control` message %s from peer %s",
rpc_incoming.control,
peer_id,
)
await self.router.handle_rpc(rpc_incoming, peer_id)
# Force context switch

View File

@ -8,9 +8,6 @@ extras_require = {
"factory-boy>=2.12.0,<3.0.0",
"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",

View File

@ -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 = []
@ -132,6 +165,8 @@ async def py_to_daemon_stream_pair(hosts, p2pds, is_to_fail_daemon_stream):
event_stream_handled.set()
await p2pd.control.stream_handler(protocol_id, daemon_stream_handler)
# Sleep for a while to wait for the handler being registered.
await asyncio.sleep(0.01)
if is_to_fail_daemon_stream:
# FIXME: This is a workaround to make daemon reset the stream.
@ -147,5 +182,5 @@ async def py_to_daemon_stream_pair(hosts, p2pds, is_to_fail_daemon_stream):
stream_py = await host.new_stream(p2pd.peer_id, [protocol_id])
if not is_to_fail_daemon_stream:
await event_stream_handled.wait()
# NOTE: If `is_to_fail_daemon_stream == True`, `stream_daemon == None`.
# NOTE: If `is_to_fail_daemon_stream == True`, then `stream_daemon == None`.
yield stream_py, stream_daemon

View File

@ -38,7 +38,7 @@ async def p2pd_subscribe(p2pd, topic) -> "asyncio.Queue[rpc_pb2.Message]":
ps_msg.ParseFromString(msg_bytes)
# Fill in the message used in py-libp2p
msg = rpc_pb2.Message(
from_id=ps_msg.from_field,
from_id=ps_msg.from_id,
data=ps_msg.data,
seqno=ps_msg.seqno,
topicIDs=ps_msg.topicIDs,

24
tox.ini
View File

@ -15,7 +15,7 @@ select = B,C,E,F,W,T4,B9
[isort]
force_sort_within_sections=True
known_third_party=pytest,p2pclient
known_third_party=pytest,p2pclient,pexpect
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
@ -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: pytest tests/
basepython =
py37: python3.7
@ -40,6 +39,17 @@ 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
pexpect
passenv = CI TRAVIS TRAVIS_* GOPATH
extras = test
commands =
pytest tests_interop/
basepython =
py37: python3.7