Skip to content

Commit

Permalink
chore(clippy): fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Totodore committed Dec 21, 2024
1 parent eb38e50 commit 8e03927
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 34 deletions.
5 changes: 1 addition & 4 deletions crates/socketioxide-redis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,4 @@ socketioxide = { path = "../socketioxide", features = [
tracing-subscriber.workspace = true

[features]
__test_harness = [
"socketioxide/__test_harness",
"socketioxide-core/__test_harness",
]
__test_harness = ["socketioxide-core/__test_harness"]
13 changes: 4 additions & 9 deletions crates/socketioxide-redis/src/drivers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,14 @@ pub mod test {

use super::MessageStream;

type ChanItem = (String, Vec<u8>);
pub struct StubDriver {
tx: mpsc::Sender<(String, Vec<u8>)>,
tx: mpsc::Sender<ChanItem>,
handlers: Arc<RwLock<HashMap<String, mpsc::Sender<Vec<u8>>>>>,
num_serv: u16,
}
async fn pipe_handers(
mut rx: mpsc::Receiver<(String, Vec<u8>)>,
mut rx: mpsc::Receiver<ChanItem>,
handlers: Arc<RwLock<HashMap<String, mpsc::Sender<Vec<u8>>>>>,
) {
while let Some((chan, data)) = rx.recv().await {
Expand All @@ -96,13 +97,7 @@ pub mod test {
}
}
impl StubDriver {
pub fn new(
num_serv: u16,
) -> (
Self,
mpsc::Receiver<(String, Vec<u8>)>,
mpsc::Sender<(String, Vec<u8>)>,
) {
pub fn new(num_serv: u16) -> (Self, mpsc::Receiver<ChanItem>, mpsc::Sender<ChanItem>) {
let (tx, rx) = mpsc::channel(255); // driver emitter
let (tx1, rx1) = mpsc::channel(255); // driver receiver
let handlers = Arc::new(RwLock::new(HashMap::<_, mpsc::Sender<Vec<u8>>>::new()));
Expand Down
6 changes: 3 additions & 3 deletions crates/socketioxide-redis/src/drivers/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use super::{Driver, MessageStream};
#[derive(Debug)]
pub struct RedisError(redis::RedisError);

impl Into<AdapterError> for RedisError {
fn into(self) -> AdapterError {
AdapterError::from(Box::new(self.0) as Box<dyn std::error::Error + Send>)
impl From<RedisError> for AdapterError {
fn from(err: RedisError) -> Self {
AdapterError::from(Box::new(err.0) as Box<dyn std::error::Error + Send>)
}
}
impl From<redis::RedisError> for RedisError {
Expand Down
2 changes: 1 addition & 1 deletion crates/socketioxide-redis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ impl<E: SocketEmitter, R: Driver> CoreAdapter<E> for RedisAdapter<E, R> {
}

async fn close(&self) -> Result<(), Self::Error> {
self.driver.unsubscribe(&self.local.path()).await?;
self.driver.unsubscribe(self.local.path()).await?;
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion crates/socketioxide-redis/tests/broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub async fn broadcast_rooms() {
let handler = |room: &'static str, to: &'static str| {
move |socket: SocketRef<_>| async move {
// delay to ensure all socket/servers are connected
socket.join(room).await.unwrap();
socket.join(room);
tokio::time::sleep(tokio::time::Duration::from_millis(5)).await;
socket.to(to).emit("test", room).await.unwrap();
}
Expand Down
20 changes: 4 additions & 16 deletions crates/socketioxide-redis/tests/rooms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ mod fixture;
#[tokio::test]
pub async fn all_rooms() {
let [io1, io2, io3] = fixture::spawn_servers();
let handler = |rooms: &'static [&'static str]| {
move |socket: SocketRef<_>| async move {
socket.join(rooms).await.unwrap();
}
};
let handler = |rooms: &'static [&'static str]| move |socket: SocketRef<_>| socket.join(rooms);

io1.ns("/", handler(&["room1", "room2"]));
io2.ns("/", handler(&["room2", "room3"]));
Expand All @@ -25,7 +21,7 @@ pub async fn all_rooms() {
timeout_rcv!(&mut rx2); // Connect "/" packet
timeout_rcv!(&mut rx3); // Connect "/" packet

const ROOMS: [&'static str; 3] = ["room1", "room2", "room3"];
const ROOMS: [&str; 3] = ["room1", "room2", "room3"];
for io in [io1, io2, io3] {
let mut rooms = io.rooms().await.unwrap();
rooms.sort();
Expand All @@ -38,11 +34,7 @@ pub async fn all_rooms() {
}
#[tokio::test]
pub async fn add_sockets() {
let handler = |room: &'static str| {
move |socket: SocketRef<_>| async move {
socket.join(room).await.unwrap();
}
};
let handler = |room: &'static str| move |socket: SocketRef<_>| socket.join(room);
let [io1, io2] = fixture::spawn_servers();

io1.ns("/", handler("room1"));
Expand All @@ -64,11 +56,7 @@ pub async fn add_sockets() {

#[tokio::test]
pub async fn del_sockets() {
let handler = |rooms: &'static [&'static str]| {
move |socket: SocketRef<_>| async move {
socket.join(rooms).await.unwrap();
}
};
let handler = |rooms: &'static [&'static str]| move |socket: SocketRef<_>| socket.join(rooms);
let [io1, io2] = fixture::spawn_servers();

io1.ns("/", handler(&["room1", "room2"]));
Expand Down

0 comments on commit 8e03927

Please sign in to comment.