Skip to content

Commit

Permalink
No serialize of test.
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen committed Jun 22, 2023
1 parent 0a65761 commit 2ebcc71
Showing 1 changed file with 51 additions and 24 deletions.
75 changes: 51 additions & 24 deletions test/sub_transport/test_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pymodbus.transport.transport import CommType


BASE_PORT = 6100
COMM_TYPES = [
CommType.TCP,
CommType.TLS,
Expand All @@ -18,56 +19,82 @@
class TestCommTransport:
"""Test for the transport module."""

@pytest.mark.xdist_group(name="server_serialize")
@pytest.mark.parametrize("use_comm_type", COMM_TYPES)
async def test_connect(self, client, use_comm_type, use_port):
@pytest.mark.parametrize(
("use_comm_type", "use_port"),
[
(CommType.TCP, BASE_PORT + 1),
(CommType.TLS, BASE_PORT + 2),
# (CommType.UDP, BASE_PORT + 3), udp is connectionless.
(CommType.SERIAL, BASE_PORT + 4),
],
)
async def test_connect(self, client):
"""Test connect()."""
if use_comm_type == CommType.UDP:
# always true, since udp is connectionless.
return
start = time.time()
assert not await client.transport_connect()
delta = time.time() - start
assert delta < client.comm_params.timeout_connect * 1.2
client.close()

@pytest.mark.xdist_group(name="server_serialize")
@pytest.mark.parametrize("use_comm_type", COMM_TYPES)
async def test_connect_not_ok(self, client, use_comm_type, use_port):
@pytest.mark.parametrize(
("use_comm_type", "use_port"),
[
(CommType.TCP, BASE_PORT + 5),
(CommType.TLS, BASE_PORT + 6),
# (CommType.UDP, BASE_PORT + 7), udp is connectionless.
(CommType.SERIAL, BASE_PORT + 8),
],
)
async def test_connect_not_ok(self, client):
"""Test connect()."""
if use_comm_type == CommType.UDP:
# always true, since udp is connectionless.
return
client.comm_params.host = "/illegal_host"
start = time.time()
assert not await client.transport_connect()
delta = time.time() - start
assert delta < client.comm_params.timeout_connect * 1.2
client.close()

@pytest.mark.xdist_group(name="server_serialize")
@pytest.mark.parametrize("use_comm_type", COMM_TYPES)
async def test_listen(self, server, use_comm_type):
@pytest.mark.parametrize(
("use_comm_type", "use_port"),
[
(CommType.TCP, BASE_PORT + 9),
(CommType.TLS, BASE_PORT + 10),
(CommType.UDP, BASE_PORT + 11),
# (CommType.SERIAL, BASE_PORT + 12), there are no standard tty port
],
)
async def test_listen(self, server):
"""Test listen()."""
if use_comm_type == CommType.SERIAL:
# there are no positive test, since there are no standard tty port
return
assert await server.transport_listen()
assert server.transport
server.close()

@pytest.mark.xdist_group(name="server_serialize")
@pytest.mark.parametrize("use_comm_type", COMM_TYPES)
async def test_listen_not_ok(self, server, use_comm_type):
@pytest.mark.parametrize(
("use_comm_type", "use_port"),
[
(CommType.TCP, BASE_PORT + 13),
(CommType.TLS, BASE_PORT + 14),
(CommType.UDP, BASE_PORT + 15),
(CommType.SERIAL, BASE_PORT + 16),
],
)
async def test_listen_not_ok(self, server):
"""Test listen()."""
server.comm_params.host = "/illegal_host"
assert not await server.transport_listen()
assert not server.transport
server.close()

@pytest.mark.xdist_group(name="server_serialize")
@pytest.mark.parametrize("use_comm_type", COMM_TYPES)
async def test_connected(self, client, server, use_comm_type, commparams):
@pytest.mark.parametrize(
("use_comm_type", "use_port"),
[
(CommType.TCP, BASE_PORT + 13),
(CommType.TLS, BASE_PORT + 14),
(CommType.UDP, BASE_PORT + 15),
(CommType.SERIAL, BASE_PORT + 16),
],
)
async def test_connected(self, client, server, use_comm_type):
"""Test connection and data exchange."""
assert await server.transport_listen()
assert await client.transport_connect()
Expand Down

0 comments on commit 2ebcc71

Please sign in to comment.