Make two more link and media tests independent of how long the machine takes

Beyond the list of this round, found by its load runs and rarer than the tests
of the list: in about 500 runs of the whole voelin-core lib beside 32 busy
loops, a_scope_bigger_than_the_channel_is_sent_in_bigger_chunks failed 3 times
(the scope had 1 channel, not 5,003) and streamer_sends_opus 2 times (the
`video too` expectation). The fixes are of the mechanism the code shows; the
runs after them (docs/testing/load.md) are too few to count a rate that low.

a_scope_...: the connector waits 250 ms for a link's first snapshot after it
said it is connected, and the test made its 5,000 channels after saying it, so
a busy machine made the session without them. The channels are made first. The
scope is also sent whole only if the presence is in the host's state when it
is asked for, so the test now sends a voice packet of one of the presence's
clients and waits for it to come through: the link takes its events in order,
and a packet of a client comes through only once the presence is in.

streamer_sends_opus: it waited for ten frames of audio and then expected a
frame of video, but audio is made quickly and a busy machine can keep the
video encoder from its first frame for longer. It now waits for ten frames of
audio and one of video, whichever the encoders make first; its deadline, 30 s,
only ends a hang.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Sonnet 5.5 committed 2026-10-25 03:27:19 +03:00
1 parent 92d02b0e00
commit 661a607a35
2 files changed
+28 -5

No files matched your search

+20 -2
View File
@@ -1962,20 +1962,38 @@ async fn a_scope_bigger_than_the_channel_is_sent_in_bigger_chunks() {
const CHANNELS: u64 = 5_000;
let (conns, mut seen) = mpsc::unbounded_channel();
let connector = LinkConnector::new(Arc::new(Recorder(conns)), &["ts3server"]);
let (mut params, _media) = connect_params("ts3server://fake.test?port=9987");
let (mut params, mut media) = connect_params("ts3server://fake.test?port=9987");
params.credential = Credential::Foreign { kind: "teamspeak", blob: Default::default() };
params.push_capacity = 1;
let connecting = tokio::spawn(connector.connect(params));
let inner = within("the link to be asked", seen.recv()).await;
inner.events.send(connected(everything())).unwrap();
// Made before the link is told it is connected: the connector waits only
// 250 ms for the first snapshot, and making 5,000 channels can take longer
// than that on a busy machine, which left the session without them.
let mut big = presence();
for id in 100..100 + CHANNELS {
let channel = ChannelInfo { id, name: format!("c{id}"), ..Default::default() };
big.channels.insert(id, channel);
}
inner.events.send(connected(everything())).unwrap();
inner.events.send(LinkEvent::Presence(Box::new(big))).unwrap();
let connected = within("a session", async { connecting.await.ok().and_then(Result::ok) }).await;
let (session, mut pushes) = (connected.session, connected.pushes);
// The scope is sent whole only if the presence is in the host's state when
// it is asked for. The link takes its events in order, and a voice packet
// of one of the presence's clients comes through only once the presence
// is in: the packet says it is.
inner
.events
.send(LinkEvent::Audio(VoicePacket {
talker: TalkerId(8),
seq: 1,
codec: VoiceCodec::Voice,
whisper: false,
payload: OPUS_20_MS.to_vec(),
}))
.unwrap();
within("the voice", media.recv()).await;
let server = ScopeId::Server(1);
session.request(subscribe(server)).await.unwrap();
+8 -3
View File
@@ -4274,9 +4274,14 @@ mod tests {
assert!(streamer.has_audio(), "{:?}", streamer.audio_error());
let mut source = EncodedSource::new(streamer);
let mut frames = Vec::new();
let deadline = Instant::now() + Duration::from_secs(5);
while frames.iter().filter(|f: &&EncodedFrame| f.kind == MediaKind::Audio).count() < 10 {
assert!(Instant::now() < deadline, "no audio");
// Ten frames of audio and one of video, whichever the encoders make first:
// 20 ms of audio is quickly made, and a busy machine can keep the video
// encoder from its first frame for longer than that. The deadline only ends
// a hang.
let deadline = Instant::now() + Duration::from_secs(30);
let count = |frames: &[EncodedFrame], kind| frames.iter().filter(|f| f.kind == kind).count();
while count(&frames, MediaKind::Audio) < 10 || count(&frames, MediaKind::Video) < 1 {
assert!(Instant::now() < deadline, "no audio or no video in {} frames", frames.len());
tokio::time::sleep(Duration::from_millis(20)).await;
source.poll_frames(Instant::now(), &mut frames);
}