mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 16:10:57 +00:00
don't manually assign port during test
fixes #89 instead of saving the multiaddr received in the listen method of the tcp transport class, read what the service is actually listening on this allow to use 0 as port and let the OS choose a free port for us
This commit is contained in:
parent
b06aec4c47
commit
2a324c0076
20
tests/transport/test_tcp.py
Normal file
20
tests/transport/test_tcp.py
Normal file
@ -0,0 +1,20 @@
|
||||
import asyncio
|
||||
|
||||
import pytest
|
||||
|
||||
from transport.tcp.tcp import _multiaddr_from_socket
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_multiaddr_from_socket():
|
||||
def handler(r, w):
|
||||
pass
|
||||
|
||||
server = await asyncio.start_server(handler, '127.0.0.1', 8000)
|
||||
assert str(_multiaddr_from_socket(server.sockets[0])) == '/ip4/127.0.0.1/tcp/8000'
|
||||
|
||||
server = await asyncio.start_server(handler, '127.0.0.1', 0)
|
||||
addr = _multiaddr_from_socket(server.sockets[0])
|
||||
assert addr.value_for_protocol('ip4') == '127.0.0.1'
|
||||
port = addr.value_for_protocol('tcp')
|
||||
assert int(port) > 0
|
||||
Reference in New Issue
Block a user