Lines
100 %
Functions
Branches
use std::time::Duration;
use tokio::sync::{OwnedSemaphorePermit, mpsc};
use super::*;
mod close_tests;
mod inflight_tests;
mod limit_tests;
mod refusal_tests;
mod reply_tests;
mod stream_tests;
struct Rig {
mux: Mux,
replies: mpsc::Receiver<String>,
refusals: mpsc::Sender<String>,
}
/// A reply in time, or `None` once the channel ended: no test waits for ever.
async fn recv(replies: &mut mpsc::Receiver<String>) -> Option<String> {
tokio::time::timeout(Duration::from_secs(30), replies.recv())
.await
.expect("a reply in time")
fn rig() -> Rig {
rig_with(ScriptCtx::new(uuid::Uuid::nil()))
fn rig_with(ctx: ScriptCtx) -> Rig {
let (mux, replies) = Mux::new(&Handle::current(), ctx, Session::new).expect("Mux::new");
let refusals = mux.replies();
Rig {
mux,
replies,
refusals,
impl Rig {
async fn next(&mut self) -> String {
recv(&mut self.replies)
.expect("the reply channel is open")
/// Sends the frame as a client of the channel would: a refusal goes to the replies.
fn frame(&mut self, frame: &str) {
if let Some(refusal) = self.mux.frame(frame) {
self.refusals.try_send(refusal).expect("room for a refusal");
async fn hold_permit(&self) -> OwnedSemaphorePermit {
Arc::clone(&self.mux.permits)
.acquire_owned()
.expect("permit")
async fn ask(&mut self, frame: &str) -> String {
self.frame(frame);
self.next().await