Skip to content

Commit 2ab1240

Browse files
authored
tests: add patchbay tests (#3986)
## Description Adds a first round of tests using our new network simulation framework, [patchbay](https://github.com/n0-computer/patchbay). Patchbay uses Linux network namespaces to create isolated network topologies with routers, NATs, and link impairment. This lets us test actual holepunching and NAT traversal in realistic conditions, without needing any external infrastructure. The test suite covers establishing a direct path in different scenarios: - Holepunching: two devices behind destination-independent NATs connect via relay, then upgrade to direct. - Uplink switching: a device changes its network uplink (v4 and v6) mid-connection and recovers a direct path. - Interface changes: network interfaces are added or removed while connected - Link outage recovery: a device goes offline and comes back, direct connection resumes - Degraded links: increasing levels of impairment (latency, jitter, packet loss) are applied to either side of a connection and holepunching still succeeds Some tests that iroh doesn't pass yet are included but marked `#[ignore]`. They should be un-ignored as we improve things. ### Running the tests On Linux, things just work with user namespace support: ```sh cargo make patchbay # expands to: cargo nextest run -p iroh --features qlog --test patchbay --profile patchbay # run a specific test with logs: RUST_LOG=trace cargo make patchbay holepunch_simple --nocapture ``` Test output is saved in `./target/testdir-current/patchbay/<test-name>`. Patchbay currently collects tracing logs for each device, qlog files (if the feature is enabled), and endpoint metrics. There's also a browser UI for viewing timelines, topologies, and logs. The UI can also be used to compare different test runs. ```sh cargo install --git https://github.com/n0-computer/patchbay patchbay-cli patchbay serve --testdir --open ``` On macOS you'll need to run the patchbay tests in a VM or container. The `patchbay` CLI includes a tool to set up a container or QEMU VM for this. ```sh # both commands default to the container backend on macOS and native on linux patchbay test -p iroh --test patchbay patchbay serve --testdir --open # use --vm to force VM mode even on linux ``` See the [patchbay docs](https://n0-computer.github.io/patchbay/) and [README](https://github.com/n0-computer/patchbay) for more details. ## Notes and open questions There's a draft PR with some more tests: #4065, but they need more thought and work to really cover what we want to test. ## Breaking Changes None. ## Change checklist - [x] Self-review. - [x] Documentation updates following the [style guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text), if relevant. - [x] Tests if relevant.
1 parent 065b448 commit 2ab1240

10 files changed

Lines changed: 1439 additions & 99 deletions

File tree

.config/nextest.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[test-groups]
2-
run-in-isolation = { max-threads = 32 }
2+
run-in-isolation = { max-threads = 32 }
33
# these are tests that must not run with other tests concurrently. All tests in
44
# this group can take up at most 32 threads among them, but each one requiring
55
# 16 threads also. The effect should be that tests run isolated.
@@ -15,4 +15,12 @@ test-group = 'run-in-isolation'
1515
threads-required = 32
1616

1717
[profile.default]
18+
default-filter = 'not binary(patchbay)'
1819
slow-timeout = { period = "10s", terminate-after = 3 }
20+
21+
[profile.patchbay]
22+
fail-fast = false
23+
retries = 1
24+
test-threads = 4
25+
default-filter = 'binary(patchbay)'
26+
slow-timeout = { period = "30s", terminate-after = 4 }

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ jobs:
3131
if: "github.event_name != 'pull_request' || ! contains(github.event.pull_request.labels.*.name, 'flaky-test')"
3232
timeout-minutes: 30
3333
runs-on: [self-hosted, linux, X64]
34+
env:
35+
RUSTFLAGS: "-Dwarnings --cfg skip_patchbay"
3436
strategy:
3537
fail-fast: false
3638
matrix:
@@ -135,6 +137,8 @@ jobs:
135137
matrix:
136138
target:
137139
- i686-unknown-linux-gnu
140+
env:
141+
RUSTFLAGS: "-Dwarnings --cfg skip_patchbay"
138142
steps:
139143
- name: Checkout
140144
uses: actions/checkout@v6

.github/workflows/patchbay.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Patchbay Tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
concurrency:
10+
group: patchbay-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
11+
cancel-in-progress: true
12+
13+
env:
14+
RUST_BACKTRACE: 1
15+
SCCACHE_CACHE_SIZE: "10G"
16+
IROH_FORCE_STAGING_RELAYS: "1"
17+
NEXTEST_VERSION: "0.9.80"
18+
19+
jobs:
20+
patchbay_tests:
21+
name: Patchbay Tests
22+
timeout-minutes: 15
23+
runs-on: [self-hosted, linux, X64]
24+
env:
25+
RUSTC_WRAPPER: "sccache"
26+
steps:
27+
- name: Enable unprivileged user namespaces
28+
run: sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
29+
continue-on-error: true
30+
31+
- uses: actions/checkout@v6
32+
- uses: dtolnay/rust-toolchain@stable
33+
- uses: mozilla-actions/sccache-action@v0.0.9
34+
- name: Install cargo-make and cargo-nextest
35+
uses: taiki-e/install-action@v2
36+
with:
37+
tool: nextest@${{ env.NEXTEST_VERSION }},cargo-make
38+
39+
- name: Build patchbay tests
40+
run: cargo make patchbay --no-run
41+
42+
- name: Run patchbay tests
43+
id: tests
44+
run: cargo make patchbay
45+
env:
46+
RUST_LOG: ${{ runner.debug && 'trace' || 'debug' }}
47+
PATCHBAY_LOG: trace
48+
49+
- name: Upload test results
50+
if: always()
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: patchbay-testdir-${{ github.sha }}
54+
path: target/testdir-current/
55+
retention-days: 7
56+
if-no-files-found: ignore

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/target
22
/logs
33
iroh.config.toml
4+
/.patchbay

0 commit comments

Comments
 (0)