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:
zhenyi
2026-06-11 12:11:05 +08:00
parent 06e8ee96a5
commit 821537186e
111 changed files with 10458 additions and 385 deletions
+39 -13
View File
@@ -5,7 +5,7 @@ use async_trait::async_trait;
use dashmap::DashMap;
use uuid::Uuid;
use crate::socket::adapter::{Adapter, AdapterError, BroadcastOptions, SocketInfo};
use crate::socket::adapter::{Adapter, AdapterError, BroadcastOptions, LocalSendFn, SocketInfo};
use crate::socket::packet::Packet;
pub struct LocalAdapter {
@@ -16,7 +16,7 @@ pub struct LocalAdapter {
pub socket_sids: Arc<DashMap<String, String>>,
/// socket_sid → namespace path
socket_namespace: Arc<DashMap<String, String>>,
send_fn: Arc<dyn Fn(&str, &Packet) -> Result<(), String> + Send + Sync>,
send_fn: LocalSendFn,
}
impl LocalAdapter {
@@ -68,7 +68,11 @@ impl LocalAdapter {
#[async_trait]
impl Adapter for LocalAdapter {
async fn broadcast(&self, packet: &Packet, opts: &BroadcastOptions) -> Result<(), AdapterError> {
async fn broadcast(
&self,
packet: &Packet,
opts: &BroadcastOptions,
) -> Result<(), AdapterError> {
let namespace = &packet.namespace;
let sids = self.collect_matching_sids(opts, namespace);
for sid in &sids {
@@ -87,9 +91,16 @@ impl Adapter for LocalAdapter {
Ok(())
}
async fn register(&self, socket_sid: &str, engine_sid: &str, ns: &str) -> Result<(), AdapterError> {
self.socket_sids.insert(socket_sid.to_string(), engine_sid.to_string());
self.socket_namespace.insert(socket_sid.to_string(), ns.to_string());
async fn register(
&self,
socket_sid: &str,
engine_sid: &str,
ns: &str,
) -> Result<(), AdapterError> {
self.socket_sids
.insert(socket_sid.to_string(), engine_sid.to_string());
self.socket_namespace
.insert(socket_sid.to_string(), ns.to_string());
Ok(())
}
@@ -99,8 +110,16 @@ impl Adapter for LocalAdapter {
async fn add(&self, sid: &str, room: &str, ns: &str) -> Result<(), AdapterError> {
let key = Self::room_key(ns, room);
self.rooms.entry(key).or_insert_with(HashSet::new).value_mut().insert(sid.to_string());
self.socket_rooms.entry(sid.to_string()).or_insert_with(HashSet::new).value_mut().insert(room.to_string());
self.rooms
.entry(key)
.or_default()
.value_mut()
.insert(sid.to_string());
self.socket_rooms
.entry(sid.to_string())
.or_default()
.value_mut()
.insert(room.to_string());
Ok(())
}
@@ -137,10 +156,14 @@ impl Adapter for LocalAdapter {
}
}
self.socket_sids.remove(sid);
self.socket_namespace.remove(sid);
Ok(())
}
async fn fetch_sockets(&self, opts: &BroadcastOptions) -> Result<Vec<SocketInfo>, AdapterError> {
async fn fetch_sockets(
&self,
opts: &BroadcastOptions,
) -> Result<Vec<SocketInfo>, AdapterError> {
// fetch_sockets needs namespace context; use an empty namespace to match all
// (this method is typically called for inspection, not delivery)
let sids: Vec<String> = if opts.rooms.is_empty() {
@@ -164,11 +187,13 @@ impl Adapter for LocalAdapter {
continue;
}
if self.socket_sids.contains_key(sid) {
let namespace = self.socket_namespace
let namespace = self
.socket_namespace
.get(sid)
.map(|r| r.value().clone())
.unwrap_or_default();
let rooms = self.socket_rooms
let rooms = self
.socket_rooms
.get(sid)
.map(|r| r.value().clone())
.unwrap_or_default();
@@ -183,7 +208,8 @@ impl Adapter for LocalAdapter {
}
async fn socket_rooms(&self, sid: &str) -> Result<HashSet<String>, AdapterError> {
Ok(self.socket_rooms
Ok(self
.socket_rooms
.get(sid)
.map(|r| r.value().clone())
.unwrap_or_default())
@@ -196,4 +222,4 @@ impl Adapter for LocalAdapter {
async fn close(&self) -> Result<(), AdapterError> {
Ok(())
}
}
}