diff --git a/crates/voelin-core/src/link/tests.rs b/crates/voelin-core/src/link/tests.rs index 2c6d408..faebdcd 100644 --- a/crates/voelin-core/src/link/tests.rs +++ b/crates/voelin-core/src/link/tests.rs @@ -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(); diff --git a/crates/voelin-core/src/media.rs b/crates/voelin-core/src/media.rs index 8f1f10e..d35de77 100644 --- a/crates/voelin-core/src/media.rs +++ b/crates/voelin-core/src/media.rs @@ -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); }