Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!-- Copyright (c) 2026 ZettaScale Technology -->

# Test networks

Network tests use the helpers in `tests/network_config.py`, following the
Zenoh C and C++ test harnesses. Keep each test on its own network, even when it
uses a unique key: matching, discovery, and peer-information checks can also be
affected by unrelated sessions.

- Use the `session_pair` fixture for two connected sessions. It disables multicast
and gossip, clears default endpoints, binds a loopback listener, and connects
its peer explicitly. The fixture closes both sessions after the test, including
on assertion failures. Pass listener options such as `timestamp_callback` to
the fixture's factory when needed.
- Listener helpers retry actual binds on random ports in 20000–32767, at most
16 times. Keep the successful listener open while connecting. Do not probe and
release a free port before asking Zenoh to bind it. Connectors must establish
their link within five seconds or fail.
- Command-line data-exchange tests use the `pyrun` fixture. Each test gets a
private loopback router; its child examples disable discovery and connect only
to that router in client mode. This explicitly tests routed data exchange;
the unit-test session pairs retain peer mode. The bytes example needs no
network, and the scout example uses a dedicated discovery configuration
instead. Child process groups are stopped
and reaped during teardown.
- The test runner supplies private configurations to documentation and scouting
examples. Most documentation examples use an isolated local session. The
subscriber quickstart uses an explicit loopback listener and connector.
- Tests that exercise discovery use `discovery_config()`: multicast stays on,
restricted to loopback with a separate multicast group and port.

With a built binding installed in the active Python environment:

```sh
pytest -n auto --import-mode=append
pytest tests/examples_check.py -n 4 -v --import-mode=append
```
26 changes: 26 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Copyright (c) 2026 ZettaScale Technology
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# ZettaScale Zenoh Team, <zenoh@zettascale.tech>
#
import pytest
from network_config import open_session_pair


@pytest.fixture
def session_pair(request):
def open_pair(**listener_options):
listener, connector = open_session_pair(**listener_options)
request.addfinalizer(listener.close)
request.addfinalizer(connector.close)
return listener, connector

return open_pair
Loading
Loading