Skip to content

Commit 1154485

Browse files
authored
test: stabilize flaky Rust tests (#724)
#### Overview Stabilize two Rust tests that could fail under parallel CI load: the interactive terminal job-control regression and Switchyard accounting-event assertions. - [x] I confirm this contribution is my own work, or I have the right to submit it under this project license. - [x] I searched existing issues and open pull requests, and this does not duplicate existing work. #### Details The PTY driver previously matched `AGENT_DELAY_ARMED` before Python had necessarily written the trailing newline. Under load, it could suspend the agent between those writes and then time out waiting for the SIGCONT marker. Consume the remainder of the acknowledgment line before injecting the terminal suspend character. Switchyard's managed-call test helpers previously registered process-global subscribers. Parallel tests could therefore contribute unrelated optimization events and make exact accounting assertions fail. Register those captures against the current task-local scope so each test observes only its own events. Validation: - 20 consecutive focused CLI test runs - 20 consecutive Switchyard library test runs (720 tests total) - `cargo fmt --all --check` - `cargo clippy --workspace --all-targets -- -D warnings` - `just test-rust` - `uv run pre-commit run --all-files` #### Where should the reviewer start? Start with the scope-local subscriber change in `crates/switchyard/tests/unit/component_tests.rs`, then review the PTY synchronization change in `crates/cli/tests/cli_tests.rs`. #### Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to) - Relates to: none ## Summary by CodeRabbit * **Bug Fixes** * Improved terminal command handling reliability, including more consistent processing of command output. * Improved isolation of accounting event handling to prevent cross-context interference during operations. * **Tests** * Strengthened coverage for terminal job control and accounting event processing to help ensure consistent behavior. Authors: - Will Killian (https://github.com/willkill07) Approvers: - Eric Evans II (https://github.com/ericevans-nv) URL: #724
1 parent 2b2d4d8 commit 1154485

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

crates/cli/tests/cli_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4170,6 +4170,7 @@ try:
41704170
# terminal to the child without requiring a second `fg`.
41714171
os.write(master, b"delay-next-continue\n")
41724172
read_until("AGENT_DELAY_ARMED")
4173+
read_until("\n")
41734174
os.write(master, b"\x1a")
41744175
read_until("RELAY_SHELL> ")
41754176
os.killpg(relay_group, signal.SIGCONT)

crates/switchyard/tests/unit/component_tests.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ use nemo_relay::api::llm::{
2121
LlmCallExecuteParams, LlmStreamCallExecuteParams, llm_call_execute, llm_stream_call_execute,
2222
};
2323
use nemo_relay::api::runtime::{LlmExecutionNextFn, LlmStreamExecutionNextFn, LlmStreamInner};
24-
use nemo_relay::api::subscriber::{deregister_subscriber, flush_subscribers, register_subscriber};
24+
use nemo_relay::api::scope::get_handle;
25+
use nemo_relay::api::subscriber::{
26+
deregister_subscriber, flush_subscribers, register_subscriber, scope_deregister_subscriber,
27+
scope_register_subscriber,
28+
};
2529
use nemo_relay::codec::optimization::LlmOptimizationSummaryStatus;
2630
use nemo_relay::error::{UpstreamFailure, UpstreamFailureClass};
2731
use nemo_relay::plugin::rollback_registrations;
@@ -1234,7 +1238,9 @@ async fn managed_buffered_events(
12341238
let subscriber_name = format!("switchyard-accounting-{}", uuid::Uuid::now_v7());
12351239
let events = Arc::new(Mutex::new(Vec::<Event>::new()));
12361240
let captured = Arc::clone(&events);
1237-
register_subscriber(
1241+
let scope_uuid = get_handle().unwrap().uuid;
1242+
scope_register_subscriber(
1243+
&scope_uuid,
12381244
&subscriber_name,
12391245
Arc::new(move |event| captured.lock().unwrap().push(event.clone())),
12401246
)
@@ -1259,7 +1265,7 @@ async fn managed_buffered_events(
12591265
.await
12601266
.unwrap();
12611267
flush_subscribers().unwrap();
1262-
deregister_subscriber(&subscriber_name).unwrap();
1268+
scope_deregister_subscriber(&scope_uuid, &subscriber_name).unwrap();
12631269
Arc::try_unwrap(events).unwrap().into_inner().unwrap()
12641270
}
12651271

@@ -1270,7 +1276,9 @@ async fn managed_stream_events(
12701276
let subscriber_name = format!("switchyard-stream-accounting-{}", uuid::Uuid::now_v7());
12711277
let events = Arc::new(Mutex::new(Vec::<Event>::new()));
12721278
let captured = Arc::clone(&events);
1273-
register_subscriber(
1279+
let scope_uuid = get_handle().unwrap().uuid;
1280+
scope_register_subscriber(
1281+
&scope_uuid,
12741282
&subscriber_name,
12751283
Arc::new(move |event| captured.lock().unwrap().push(event.clone())),
12761284
)
@@ -1299,7 +1307,7 @@ async fn managed_stream_events(
12991307
while stream.next().await.is_some() {}
13001308
drop(stream);
13011309
flush_subscribers().unwrap();
1302-
deregister_subscriber(&subscriber_name).unwrap();
1310+
scope_deregister_subscriber(&scope_uuid, &subscriber_name).unwrap();
13031311
Arc::try_unwrap(events).unwrap().into_inner().unwrap()
13041312
}
13051313

0 commit comments

Comments
 (0)