Skip to content
Open
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
89 changes: 89 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
name: Rust

# Builds and tests the Rust crates. The Meson workflow covers the C++
# plugin only, so without this nothing checks the relay, the mock server
# or baton.

on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

permissions:
contents: read

jobs:
build-and-test:
name: ${{ matrix.crate }}
runs-on: ubuntu-latest

strategy:
# Report every crate, rather than hiding the rest behind the
# first failure.
fail-fast: false
matrix:
crate:
- relay
- src/server
- xplane_plugin/subprojects/baton

steps:
- uses: actions/checkout@v4

# The relay is an iced GUI, so its dependency tree pulls in
# wayland, x11 and drm crates that need these headers present to
# build. The other two crates are plain std and need none of it.
- name: Install GUI build dependencies
if: matrix.crate == 'relay'
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends -y \
libwayland-dev \
libxkbcommon-dev \
libx11-dev \
libxcursor-dev \
libxi-dev \
libxrandr-dev \
libgl1-mesa-dev \
libudev-dev \
libfontconfig1-dev \
pkg-config

# rust-toolchain.toml at the repository root decides the version,
# so no toolchain is named here.
- name: Show toolchain
run: |
rustc --version
cargo --version

- name: Cache cargo registry and build output
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
${{ matrix.crate }}/target
key: >-
${{ runner.os }}-cargo-${{ matrix.crate }}-${{
hashFiles(format('{0}/Cargo.lock', matrix.crate)) }}
restore-keys: |
${{ runner.os }}-cargo-${{ matrix.crate }}-

# --locked builds the versions in Cargo.lock instead of re-resolving.
# relay/Cargo.toml pins iced and anyhow at "*", so without it CI can
# quietly test a different dependency set than anyone ran locally, and
# a build that passes today can break tomorrow with no commit to blame.
# It also fails loudly if a Cargo.toml change was committed without the
# matching lockfile update.
- name: Build
working-directory: ${{ matrix.crate }}
run: cargo build --locked --verbose

- name: Test
working-directory: ${{ matrix.crate }}
run: cargo test --locked --verbose
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Run from the repo root, in order, per component:
- Baton: `cd xplane_plugin/subprojects/baton && cargo test`
- Inference: `cd inference && uv sync`, then `uv run python -m pilot_inference.<group>.<module>`. `uv run pytest` runs the tests in `inference/tests/`; the event classification scripts are mostly untested.

CI is in `.github/workflows/` (`meson-build.yml`, `super-linter.yml`, `release.yml`: a `v*` tag publishes the plugin and `relay.exe` to a GitHub Release, a manual run is a dry run). Run `meson setup` with the cross-file for your OS if not on native Windows (see README).
CI is in `.github/workflows/`: `meson-build.yml` builds the C++ plugin on Windows, `rust.yml` builds and tests the three Rust crates on Ubuntu, `super-linter.yml` lints, and `release.yml` publishes the plugin and `relay.exe` to a GitHub Release on a `v*` tag (a manual run is a dry run). Run `meson setup` with the cross-file for your OS if not on native Windows (see README).

## Gotchas

Expand Down
37 changes: 24 additions & 13 deletions relay/src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,11 +827,19 @@ mod tests {
// feed to iMotions.
#[test]
fn a_python_process_that_stops_reading_is_dropped_not_waited_on() {
// The Python side never reads, so its pinned receive buffer fills and
// stays full: writes block, the 100ms timeout fires and the mirror is
// dropped. With the host's default buffers the whole run fits in the
// kernel, nothing blocks, and the timeout never fires at all.
const SAMPLES: usize = 500;
// The Python side never reads, so the buffers fill and stay full:
// writes block, the 100ms timeout fires and the mirror is dropped.
// With the host's default buffers the whole run fits in the kernel,
// nothing blocks, and the timeout never fires at all.
//
// Fed in batches until that happens rather than as one fixed burst.
// mirror_send drops into a 256-deep queue when it is full, so a burst
// does not decide how much reaches the writer thread -- the race
// between the two threads does, and a burst that loses it leaves the
// writer with far less than a bufferful and nothing ever blocks. The
// stalled reader never drains, so what the writer does get through
// accumulates across batches and the timeout is reached for certain.
const BATCH: usize = 200;

let (imotions, imotions_addr) = listener_on_free_port();
let (python, python_addr) = stalling_listener_on_free_port();
Expand Down Expand Up @@ -862,15 +870,18 @@ mod tests {
);

let started = std::time::Instant::now();
for i in 0..SAMPLES {
send_sample(&mut state, &format!("{}", 1000 + i % 100));
}
let mut samples = 0usize;
let was_dropped = wait_until(|| {
for i in 0..BATCH {
send_sample(&mut state, &format!("{}", 1000 + (samples + i) % 100));
}
samples += BATCH;
let _ = update(&mut state, Message::Update);
!state.mirror_connected
});
assert!(
wait_until(|| {
let _ = update(&mut state, Message::Update);
!state.mirror_connected
}),
"a stalled reader was never dropped"
was_dropped,
"a stalled reader was never dropped after {samples} samples"
);
let elapsed = started.elapsed();

Expand Down
Loading