Skip to content

Commit

Permalink
Update tests: remove the obsolete 'can_transmit' property; skip the l…
Browse files Browse the repository at this point in the history
…arge monitor test on Windows
  • Loading branch information
pavel-kirienko committed Jan 12, 2024
1 parent 3aa42bf commit a6d2bc4
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 76 deletions.
8 changes: 4 additions & 4 deletions tests/cmd/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async def handle_request(
return response

# Invoke the service without discovery and then run the server for a few seconds to let it process the request.
proc = Subprocess.cli( # Windows compat: -v blocks stderr pipe on Windows.
proc = Subprocess.cli(
"-j",
"call",
"22",
Expand Down Expand Up @@ -92,7 +92,7 @@ async def handle_request(

# Invoke the service with ID discovery and static type.
last_metadata = None
proc = Subprocess.cli( # Windows compat: -v blocks stderr pipe on Windows.
proc = Subprocess.cli(
"-j",
"call",
"22",
Expand Down Expand Up @@ -122,7 +122,7 @@ async def handle_request(

# Invoke the service with full discovery.
last_metadata = None
proc = Subprocess.cli( # Windows compat: -v blocks stderr pipe on Windows.
proc = Subprocess.cli(
"-j",
"call",
"22",
Expand Down Expand Up @@ -204,7 +204,7 @@ async def _unittest_call_fixed(transport_factory: TransportFactory, compiled_dsd
server_node.start()

# Invoke a fixed port-ID service.
proc = Subprocess.cli( # Windows compat: -v blocks stderr pipe on Windows.
proc = Subprocess.cli(
"-j",
"call",
"22",
Expand Down
4 changes: 4 additions & 0 deletions tests/cmd/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Author: Pavel Kirienko <[email protected]>

from typing import Any, Optional, Awaitable
import sys
import asyncio
import itertools
import pytest
Expand All @@ -13,6 +14,9 @@
from tests.dsdl import OUTPUT_DIR
import yakut

if sys.platform.startswith("win"): # pragma: no cover
pytest.skip("These tests do not work reliably on Windows", allow_module_level=True)


# noinspection SpellCheckingInspection
@pytest.mark.asyncio
Expand Down
83 changes: 34 additions & 49 deletions tests/cmd/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _unittest_pub_sub_regular(transport_factory: TransportFactory, compiled_dsdl
)
time.sleep(1.0) # Time to let the background processes finish initialization

proc_pub = Subprocess.cli( # Windows compat: -v blocks stderr pipe on Windows.
proc_pub = Subprocess.cli(
"--heartbeat-vssc=54",
"--heartbeat-priority=high",
"--node-info",
Expand Down Expand Up @@ -149,21 +149,21 @@ def _unittest_slow_cli_pub_sub_anon(transport_factory: TransportFactory, compile
"YAKUT_TRANSPORT": transport_factory(None).expression,
"YAKUT_PATH": str(OUTPUT_DIR),
}
proc_sub_heartbeat = Subprocess.cli( # Windows compat: -v blocks stderr pipe on Windows.
proc_sub_heartbeat = Subprocess.cli(
"-j",
"sub",
"uavcan.node.heartbeat",
"--with-metadata",
environment_variables=env,
)
proc_sub_diagnostic_with_meta = Subprocess.cli( # Windows compat: -v blocks stderr pipe on Windows.
proc_sub_diagnostic_with_meta = Subprocess.cli(
"-j",
"sub",
"uavcan.diagnostic.record",
"--with-metadata",
environment_variables=env,
)
proc_sub_diagnostic_no_meta = Subprocess.cli( # Windows compat: -v blocks stderr pipe on Windows.
proc_sub_diagnostic_no_meta = Subprocess.cli(
"-j",
"sub",
"uavcan.diagnostic.record",
Expand All @@ -173,53 +173,38 @@ def _unittest_slow_cli_pub_sub_anon(transport_factory: TransportFactory, compile

time.sleep(3.0) # Time to let the background processes finish initialization

if transport_factory(None).can_transmit:
proc = Subprocess.cli(
"pub",
"uavcan.diagnostic.record",
"{}",
"--count=2",
"--period=2",
environment_variables=env,
)
proc.wait(timeout=8)
proc = Subprocess.cli(
"pub",
"uavcan.diagnostic.record",
"{}",
"--count=2",
"--period=2",
environment_variables=env,
)
proc.wait(timeout=8)

time.sleep(2.0) # Time to sync up
time.sleep(2.0) # Time to sync up

assert (
proc_sub_heartbeat.wait(1.0, interrupt=True)[1].strip() == ""
), "Anonymous nodes must not broadcast heartbeat"
assert proc_sub_heartbeat.wait(1.0, interrupt=True)[1].strip() == "", "Anonymous nodes must not broadcast heartbeat"

diagnostics = list(
json.loads(s) for s in proc_sub_diagnostic_with_meta.wait(1.0, interrupt=True)[1].splitlines()
)
print("diagnostics:", diagnostics)
# Remember that anonymous transfers over redundant transports are NOT deduplicated.
# Hence, to support the case of redundant transports, we use 'greater or equal' here.
assert len(diagnostics) >= 2
for m in diagnostics:
assert "nominal" in m["8184"]["_meta_"]["priority"].lower()
assert m["8184"]["_meta_"]["transfer_id"] >= 0
assert m["8184"]["_meta_"]["source_node_id"] is None
assert m["8184"]["timestamp"]["microsecond"] == 0
assert m["8184"]["text"] == ""
diagnostics = list(json.loads(s) for s in proc_sub_diagnostic_with_meta.wait(1.0, interrupt=True)[1].splitlines())
print("diagnostics:", diagnostics)
# Remember that anonymous transfers over redundant transports are NOT deduplicated.
# Hence, to support the case of redundant transports, we use 'greater or equal' here.
assert len(diagnostics) >= 2
for m in diagnostics:
assert "nominal" in m["8184"]["_meta_"]["priority"].lower()
assert m["8184"]["_meta_"]["transfer_id"] >= 0
assert m["8184"]["_meta_"]["source_node_id"] is None
assert m["8184"]["timestamp"]["microsecond"] == 0
assert m["8184"]["text"] == ""

diagnostics = list(json.loads(s) for s in proc_sub_diagnostic_no_meta.wait(1.0, interrupt=True)[1].splitlines())
print("diagnostics:", diagnostics)
assert len(diagnostics) >= 2 # >= because see above
for m in diagnostics:
assert m["8184"]["timestamp"]["microsecond"] == 0
assert m["8184"]["text"] == ""
else:
proc = Subprocess.cli( # Windows compat: -v blocks stderr pipe on Windows.
"pub",
"uavcan.diagnostic.Record",
"{}",
"--count=2",
"--period=2",
environment_variables=env,
)
proc.wait(timeout=8, log=False)
diagnostics = list(json.loads(s) for s in proc_sub_diagnostic_no_meta.wait(1.0, interrupt=True)[1].splitlines())
print("diagnostics:", diagnostics)
assert len(diagnostics) >= 2 # >= because see above
for m in diagnostics:
assert m["8184"]["timestamp"]["microsecond"] == 0
assert m["8184"]["text"] == ""


def _unittest_e2e_discovery_pub(transport_factory: TransportFactory, compiled_dsdl: typing.Any) -> None:
Expand All @@ -238,7 +223,7 @@ def _unittest_e2e_discovery_pub(transport_factory: TransportFactory, compiled_ds
},
)
time.sleep(3.0) # Let the subscriber boot up.
proc_pub = Subprocess.cli( # Windows compat: -v blocks stderr pipe on Windows.
proc_pub = Subprocess.cli(
"pub",
"1000", # Use discovery.
"hello",
Expand All @@ -260,7 +245,7 @@ def _unittest_e2e_discovery_pub(transport_factory: TransportFactory, compiled_ds

def _unittest_e2e_discovery_sub(transport_factory: TransportFactory, compiled_dsdl: typing.Any) -> None:
_ = compiled_dsdl
proc_pub = Subprocess.cli( # Windows compat: -v blocks stderr pipe on Windows.
proc_pub = Subprocess.cli(
"pub",
"1000:uavcan.primitive.string",
"hello",
Expand Down
8 changes: 4 additions & 4 deletions tests/cmd/pubsub_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _unittest_monoclust_ts_field_auto(transport_factory: TransportFactory, compi
},
)
time.sleep(3.0)
proc_pub = Subprocess.cli( # Windows compat: -v blocks stderr pipe on Windows.
proc_pub = Subprocess.cli(
"pub",
"1000:uavcan.si.sample.mass.Scalar",
"!$ n * 1e6",
Expand Down Expand Up @@ -72,7 +72,7 @@ def _unittest_monoclust_ts_field_manual(transport_factory: TransportFactory, com
},
)
time.sleep(3.0)
proc_pub = Subprocess.cli( # Windows compat: -v blocks stderr pipe on Windows.
proc_pub = Subprocess.cli(
"pub",
"1000:uavcan.si.sample.mass.Scalar",
"!$ n * 1.00 * 1e6",
Expand Down Expand Up @@ -142,7 +142,7 @@ def _unittest_monoclust_ts_arrival_auto(transport_factory: TransportFactory, com
},
)
time.sleep(3.0)
proc_pub = Subprocess.cli( # Windows compat: -v blocks stderr pipe on Windows.
proc_pub = Subprocess.cli(
"pub",
"1000:uavcan.primitive.String",
"!$ str(n)",
Expand Down Expand Up @@ -179,7 +179,7 @@ def _unittest_transfer_id(transport_factory: TransportFactory, compiled_dsdl: ty
},
)
time.sleep(3.0)
proc_pub = Subprocess.cli( # Windows compat: -v blocks stderr pipe on Windows.
proc_pub = Subprocess.cli(
"pub",
"1000:uavcan.primitive.String",
"!$ str(n)",
Expand Down
19 changes: 0 additions & 19 deletions tests/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ class TransportConfig:
"""

expression: str
"""
Please do not use this in new tests,
consider using the environment variables instead as they are the recommended form now.
"""
can_transmit: bool
environment: dict[str, str]


Expand Down Expand Up @@ -69,7 +64,6 @@ def sudo(cmd: str, ensure_success: bool = True) -> None:
def vcan() -> typing.Iterator[TransportFactory]:
yield lambda nid: TransportConfig(
expression=f"CAN(can.media.socketcan.SocketCANMedia('vcan0',64),local_node_id={nid})",
can_transmit=True,
environment=mk_env(
nid,
UAVCAN__CAN__IFACE="socketcan:vcan0",
Expand All @@ -86,7 +80,6 @@ def vcan_tmr() -> typing.Iterator[TransportFactory]:
for idx, mtu in enumerate([8, 32, 64])
)
),
can_transmit=True,
environment=mk_env(
nid,
UAVCAN__CAN__IFACE="socketcan:vcan0 socketcan:vcan1 socketcan:vcan2",
Expand Down Expand Up @@ -114,7 +107,6 @@ def serial_tunneled_via_tcp() -> typing.Iterator[TransportFactory]:
assert broker.alive
yield lambda nid: TransportConfig(
expression=f"Serial('{serial_endpoint}',local_node_id={nid})",
can_transmit=True,
environment=mk_env(
nid,
UAVCAN__SERIAL__IFACE=serial_endpoint,
Expand All @@ -129,16 +121,6 @@ def udp_loopback() -> typing.Iterator[TransportFactory]:
yield lambda nid: (
TransportConfig(
expression=f"UDP('127.0.0.1',{nid})",
can_transmit=True,
environment=mk_env(
nid,
UAVCAN__UDP__IFACE="127.0.0.1",
),
)
if nid is not None
else TransportConfig(
expression="UDP('127.0.0.1',None)",
can_transmit=False,
environment=mk_env(
nid,
UAVCAN__UDP__IFACE="127.0.0.1",
Expand All @@ -158,7 +140,6 @@ def heterogeneous_udp_serial() -> typing.Iterator[TransportFactory]:
]
)
),
can_transmit=nid is not None,
environment=mk_env(
nid,
UAVCAN__SERIAL__IFACE=serial_endpoint,
Expand Down

0 comments on commit a6d2bc4

Please sign in to comment.