- 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>
125 lines
4.1 KiB
Rust
125 lines
4.1 KiB
Rust
//! 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");
|
|
}
|