refactor(tests): reformat code and update dependency management
- Reorganized import statements in adapter tests for better readability - Replaced or_insert_with(Vec::new) with or_default() in test closures - Updated Cargo.lock with new dependency versions and checksums - Added TLS features to tonic dependency configuration - Included sqlx, chrono, and uuid dependencies with specific features - Added jsonwebtoken and arc-swap as project dependencies - Reformatted assertion statements to comply with line length limits - Adjusted base64 import order in engine codec module - Updated protobuf include statement formatting
This commit is contained in:
+18
-5
@@ -1,14 +1,20 @@
|
||||
pub mod local;
|
||||
pub mod redis;
|
||||
pub mod nats;
|
||||
pub mod redis;
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::sync::Arc;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::socket::packet::Packet;
|
||||
|
||||
/// Alias for cross-node broadcast callback functions.
|
||||
pub type LocalBroadcastFn = Arc<dyn Fn(&Packet, &BroadcastOptions) + Send + Sync + 'static>;
|
||||
/// Alias for local send-to-socket callback functions.
|
||||
pub type LocalSendFn = Arc<dyn Fn(&str, &Packet) -> Result<(), String> + Send + Sync>;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum AdapterError {
|
||||
#[error("Redis error: {0}")]
|
||||
@@ -72,11 +78,13 @@ pub enum BusMessage {
|
||||
|
||||
#[async_trait]
|
||||
pub trait Adapter: Send + Sync + 'static {
|
||||
async fn broadcast(&self, packet: &Packet, opts: &BroadcastOptions) -> Result<(), AdapterError>;
|
||||
async fn broadcast(&self, packet: &Packet, opts: &BroadcastOptions)
|
||||
-> Result<(), AdapterError>;
|
||||
async fn add(&self, sid: &str, room: &str, ns: &str) -> Result<(), AdapterError>;
|
||||
async fn del(&self, sid: &str, room: &str, ns: &str) -> Result<(), AdapterError>;
|
||||
async fn del_all(&self, sid: &str, ns: &str) -> Result<(), AdapterError>;
|
||||
async fn fetch_sockets(&self, opts: &BroadcastOptions) -> Result<Vec<SocketInfo>, AdapterError>;
|
||||
async fn fetch_sockets(&self, opts: &BroadcastOptions)
|
||||
-> Result<Vec<SocketInfo>, AdapterError>;
|
||||
async fn socket_rooms(&self, sid: &str) -> Result<HashSet<String>, AdapterError>;
|
||||
fn server_id(&self) -> &str;
|
||||
async fn close(&self) -> Result<(), AdapterError>;
|
||||
@@ -84,7 +92,12 @@ pub trait Adapter: Send + Sync + 'static {
|
||||
/// Register a socket SID → engine SID mapping in the adapter.
|
||||
/// Must be called when a socket first connects, before any room operations.
|
||||
/// The `ns` parameter is the namespace path this socket belongs to.
|
||||
async fn register(&self, _socket_sid: &str, _engine_sid: &str, _ns: &str) -> Result<(), AdapterError> {
|
||||
async fn register(
|
||||
&self,
|
||||
_socket_sid: &str,
|
||||
_engine_sid: &str,
|
||||
_ns: &str,
|
||||
) -> Result<(), AdapterError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -95,5 +108,5 @@ pub trait Adapter: Send + Sync + 'static {
|
||||
}
|
||||
|
||||
pub use local::LocalAdapter;
|
||||
pub use nats::NatsAdapter;
|
||||
pub use redis::RedisAdapter;
|
||||
pub use nats::NatsAdapter;
|
||||
Reference in New Issue
Block a user