Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions mocktail/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! Mock server
use std::{
cell::OnceCell,
net::{IpAddr, Ipv4Addr, SocketAddr, TcpStream},
sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard},
sync::{Arc, OnceLock, RwLock, RwLockReadGuard, RwLockWriteGuard},
time::Duration,
};

Expand All @@ -12,7 +11,8 @@ use hyper_util::{
rt::{TokioExecutor, TokioIo},
server::conn,
};
use rand::Rng;
use rand::rngs::SmallRng;
use rand::{Rng, SeedableRng};
use tokio::net::TcpListener;
use tracing::{debug, error, info};
use url::Url;
Expand All @@ -29,8 +29,8 @@ use crate::{
pub struct MockServer {
name: &'static str,
kind: ServerKind,
addr: OnceCell<SocketAddr>,
base_url: OnceCell<Url>,
addr: OnceLock<SocketAddr>,
base_url: OnceLock<Url>,
state: Arc<MockServerState>,
config: MockServerConfig,
}
Expand All @@ -41,8 +41,8 @@ impl MockServer {
Self {
name,
kind: ServerKind::Http,
addr: OnceCell::new(),
base_url: OnceCell::new(),
addr: OnceLock::new(),
base_url: OnceLock::new(),
state: Arc::new(MockServerState::default()),
config: MockServerConfig::default(),
}
Expand Down Expand Up @@ -72,7 +72,7 @@ impl MockServer {
}

let mut counter = 0;
let mut rng = rand::rng();
let mut rng = SmallRng::from_os_rng();

let listener = loop {
let port: u16 =
Expand Down Expand Up @@ -285,3 +285,14 @@ impl Default for MockServerConfig {
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_mock_server_send() {
fn is_send<T: Send>() {}
is_send::<MockServer>();
}
}