Measure the voice path through both adapters; test the engine on a registered connector
- A unit test frames 5,000 Opus packets each way through SessionLink, the TeamSpeak session and the recording link and prints the cost per packet (about 7 microseconds to the host, 10 from it in a debug build; the test bounds each direction at 500 microseconds). docs/session-seam.md section 13 records the figures, which were the one thing slice 1 had not measured. - tests/session_backends.rs: the engine over voelin-proto's FakeConnector through Engine::start_with_backends (connect, server name and backend, channels, a move, disconnect), and the registry's error text for an address no connector serves. - The error of a TeamSpeak connector given an address that is not a TeamSpeak one no longer prints the query, where a channel password rides. - The note on the two library tests that need the name localhost to resolve to 127.0.0.1 says so. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1b7abdf4c7
commit
bc9ccbc85e
4 files changed
+184
-9
No files matched your search
@@ -1433,3 +1433,44 @@ async fn the_engine_consumes_any_session_a_connector_makes() {
|
||||
assert_eq!(reason, None);
|
||||
assert_eq!(connector.connects().len(), 1);
|
||||
}
|
||||
|
||||
/// What the second adapter costs per voice packet (the last row of the risk
|
||||
/// table in `docs/session-seam.md`): every packet is framed as RTP and taken
|
||||
/// apart again on its way, in each direction. A generous bound in a debug
|
||||
/// build; the figures are printed.
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn a_voice_packet_costs_microseconds_through_both_adapters() {
|
||||
const PACKETS: usize = 5_000;
|
||||
let mut rig = Rig::new(everything()).await;
|
||||
let started = std::time::Instant::now();
|
||||
for _ in 0..PACKETS {
|
||||
rig.give(LinkCmd::Audio(EncodedVoice {
|
||||
codec: VoiceCodec::Voice,
|
||||
payload: OPUS_20_MS.to_vec(),
|
||||
}));
|
||||
}
|
||||
for _ in 0..PACKETS {
|
||||
assert!(matches!(rig.inner_cmd().await, LinkCmd::Audio(_)));
|
||||
}
|
||||
let uplink = started.elapsed() / PACKETS as u32;
|
||||
|
||||
let started = std::time::Instant::now();
|
||||
for seq in 0..PACKETS {
|
||||
rig.play(LinkEvent::Audio(VoicePacket {
|
||||
talker: TalkerId(8),
|
||||
seq: seq as u16,
|
||||
codec: VoiceCodec::Voice,
|
||||
whisper: false,
|
||||
payload: OPUS_20_MS.to_vec(),
|
||||
}));
|
||||
}
|
||||
let mut heard = 0;
|
||||
while heard < PACKETS {
|
||||
rig.event(|e| matches!(e, LinkEvent::Audio(_)).then_some(())).await;
|
||||
heard += 1;
|
||||
}
|
||||
let downlink = started.elapsed() / PACKETS as u32;
|
||||
eprintln!("voice through both adapters: {uplink:?} per packet up, {downlink:?} down");
|
||||
assert!(uplink < Duration::from_micros(500), "{uplink:?}");
|
||||
assert!(downlink < Duration::from_micros(500), "{downlink:?}");
|
||||
}
|
||||
@@ -147,10 +147,9 @@ fn inner_options(params: &ConnectParams, ctx: &LocalCtx) -> Result<ConnectOption
|
||||
let link = match Link::parse(¶ms.address) {
|
||||
Some(Link::Server(link)) => link,
|
||||
_ => {
|
||||
return Err(SessionError::Protocol(format!(
|
||||
"not a TeamSpeak server address: {}",
|
||||
params.address
|
||||
)));
|
||||
// Without the query: a channel password rides in it.
|
||||
let shown = params.address.split('?').next().unwrap_or_default();
|
||||
return Err(SessionError::Protocol(format!("not a TeamSpeak server address: {shown}")));
|
||||
}
|
||||
};
|
||||
let identity = match ¶ms.credential {
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
//! The engine on a `voelin_proto::link::Session` that no TeamSpeak code
|
||||
//! made: `Engine::start_with_backends` takes the connector registry, and the
|
||||
//! scheme of a session's address picks the connector. The fake host of the
|
||||
//! protocol repository stands for a Voelin host here (the fuller tests of the
|
||||
//! seam on the fake host come with the next slice of
|
||||
//! `docs/session-seam.md`).
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use tokio::sync::broadcast;
|
||||
use voelin_core::settings::Settings;
|
||||
use voelin_core::{
|
||||
Backends, Command, Engine, Event, History, SessionState, VoiceOptions, VoiceState,
|
||||
};
|
||||
use voelin_proto::test_util::FakeConnector;
|
||||
use voelin_proto::v1::{self, entity::Kind};
|
||||
|
||||
const SESSION: u64 = 1;
|
||||
|
||||
async fn next<T>(
|
||||
events: &mut broadcast::Receiver<Event>,
|
||||
mut f: impl FnMut(Event) -> Option<T>,
|
||||
) -> T {
|
||||
tokio::time::timeout(Duration::from_secs(10), async {
|
||||
loop {
|
||||
if let Some(t) = f(events.recv().await.expect("engine events")) {
|
||||
return t;
|
||||
}
|
||||
}
|
||||
})
|
||||
.await
|
||||
.expect("an event in time")
|
||||
}
|
||||
|
||||
fn host_with_two_channels(connector: &FakeConnector) {
|
||||
let host = connector.host();
|
||||
let put = |kind: Kind| host.put(v1::Entity { kind: Some(kind) }).unwrap();
|
||||
put(Kind::Server(v1::Server {
|
||||
id: 1,
|
||||
name: "Fake Host".into(),
|
||||
uid: "fake-host".into(),
|
||||
default_channel_id: 10,
|
||||
..Default::default()
|
||||
}));
|
||||
for (id, name, position) in [(10, "Lobby", 0), (11, "Games", 1024)] {
|
||||
put(Kind::Channel(v1::Channel {
|
||||
id,
|
||||
server_id: 1,
|
||||
kind: v1::ChannelKind::Voice as i32,
|
||||
name: name.into(),
|
||||
position,
|
||||
..Default::default()
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn a_session_of_a_registered_connector_is_the_engines_voice_source() {
|
||||
let connector = FakeConnector::new();
|
||||
host_with_two_channels(&connector);
|
||||
let mut backends = Backends::empty();
|
||||
backends.register(Arc::new(connector.clone()));
|
||||
let engine = Engine::start_with_backends(Settings::in_memory(), History::in_memory(), backends);
|
||||
let mut events = engine.subscribe();
|
||||
|
||||
engine.send(Command::ConnectVoice {
|
||||
session: SESSION,
|
||||
options: Box::new(VoiceOptions::new("fake://host", "tester")),
|
||||
});
|
||||
let (name, backend) = next(&mut events, |e| match e {
|
||||
Event::ServerInfo { name, backend, .. } => Some((name, backend)),
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
assert_eq!((name.as_str(), backend.product.as_str()), ("Fake Host", "voelin-fake"));
|
||||
let presence = next(&mut events, |e| match e {
|
||||
Event::Presence { presence, .. } if !presence.channels.is_empty() => Some(presence),
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
let channels: Vec<_> =
|
||||
presence.channels.values().map(|c| (c.id, c.name.as_str(), c.order)).collect();
|
||||
assert_eq!(channels, [(10, "Lobby", 0), (11, "Games", 10)]);
|
||||
// The host was asked once, with the nickname and the TeamSpeak-shaped
|
||||
// credential the engine makes of its options for now.
|
||||
let connects = connector.connects();
|
||||
assert_eq!(connects.len(), 1);
|
||||
assert_eq!(connects[0].address, "fake://host");
|
||||
assert_eq!(connects[0].hello.nickname, "tester");
|
||||
|
||||
// A move is a request to the host; the host's voice state is where we are.
|
||||
engine.send(Command::MoveToChannel { session: SESSION, channel: 11, password: None });
|
||||
let state: SessionState = next(&mut events, |e| match e {
|
||||
Event::State { state, .. } if state.own_channel == Some(11) => Some(state),
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
assert_eq!(state.voice, VoiceState::Connected);
|
||||
|
||||
engine.send(Command::DisconnectVoice { session: SESSION });
|
||||
next(&mut events, |e| match e {
|
||||
Event::State { state, .. } if state.voice == VoiceState::Disconnected => Some(()),
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn an_address_no_connector_serves_fails_with_the_registry_s_words() {
|
||||
let engine =
|
||||
Engine::start_with_backends(Settings::in_memory(), History::in_memory(), Backends::empty());
|
||||
let mut events = engine.subscribe();
|
||||
engine.send(Command::ConnectVoice {
|
||||
session: SESSION,
|
||||
options: Box::new(VoiceOptions::new("voelin://host/i/code", "tester")),
|
||||
});
|
||||
let error = next(&mut events, |e| match e {
|
||||
Event::Error { message, .. } => Some(message),
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
assert_eq!(error, "voice: no connector for voelin://host/i/code");
|
||||
}
|
||||
Reference in new issue
Block a user