Files
codex/codex-rs/voice-host/src/transport_runtime_tests.rs
T
Benjamin Carlsson 1b53f6a44e Add WebRTC negotiation to the voice host (#42676)
## What changed

- Add helper protocol requests to create a WebRTC offer, apply an answer, and report readiness once the ordered `oai-events` data channel opens.
- Support UDP and TCP candidates while bounding signaling size, remote candidates, inbound TCP streams, and WebRTC buffers. Redact session descriptions and peer errors from diagnostics.
- Close unexpected remote data channels and tear down the peer during helper shutdown, including when the parent pipe is lost during startup.

## Testing

- Exercise offer/answer negotiation and clean shutdown over real UDP and TCP sockets.
- Cover signaling validation, candidate and connection limits, early packet loss, slow TCP connection setup, and blocked-startup parent loss.

GitOrigin-RevId: 5f5e60a3a4d1d8eaca2e4724e66284f54061b6af
2026-09-04 05:07:02 +00:00

56 lines
2.0 KiB
Rust

//! Exercise admission and slot reuse with real TCP sockets across multiple listeners.
use super::*;
use pretty_assertions::assert_eq;
use tokio::time::timeout;
#[tokio::test]
async fn caps_inbound_streams_and_reuses_slots_across_listeners() {
timeout(Duration::from_secs(/*secs*/ 10), async {
let runtime = VoiceRuntime::default();
let first = runtime
.wrap_tcp_listener(std::net::TcpListener::bind("127.0.0.1:0").unwrap())
.unwrap();
let second = runtime
.wrap_tcp_listener(std::net::TcpListener::bind("127.0.0.1:0").unwrap())
.unwrap();
let mut clients = Vec::new();
let mut streams = Vec::new();
for _ in 0..MAX_INBOUND_STREAMS {
clients.push(
runtime
.connect_tcp(first.local_addr().unwrap())
.await
.unwrap(),
);
streams.push(first.accept().await.unwrap().0);
}
// A second listener shares the budget; rejecting a connection closes its socket.
let rejected = runtime
.connect_tcp(second.local_addr().unwrap())
.await
.unwrap();
assert_eq!(
second.accept().await.unwrap_err().to_string(),
"voice TCP connection limit reached"
);
assert_eq!(rejected.read(&mut [0]).await.unwrap(), 0);
assert_eq!(runtime.accepted.lock().unwrap().len(), MAX_INBOUND_STREAMS);
drop(streams.pop());
let replacement = runtime
.connect_tcp(second.local_addr().unwrap())
.await
.unwrap();
let (accepted, _) = second.accept().await.unwrap();
replacement.write_all(b"x").await.unwrap();
let mut byte = [0];
assert_eq!(accepted.read(&mut byte).await.unwrap(), 1);
assert_eq!(byte, *b"x");
assert_eq!(runtime.accepted.lock().unwrap().len(), MAX_INBOUND_STREAMS);
drop((clients, streams, accepted, replacement));
})
.await
.unwrap();
}