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
+27 -2
View File
@@ -1,6 +1,8 @@
use std::sync::OnceLock;
use std::sync::atomic::{AtomicU64, Ordering};
use tokio::sync::mpsc;
use uuid::Uuid;
use crate::socket::packet::Packet;
@@ -8,10 +10,13 @@ pub struct Socket {
pub sid: String,
pub namespace: String,
pub engine_sid: String,
/// Authenticated user ID, set once during `on_connect`.
user_id: OnceLock<Uuid>,
ack_id: AtomicU64,
tx: mpsc::Sender<Packet>,
}
#[allow(clippy::result_large_err)]
impl Socket {
pub fn new(
sid: String,
@@ -24,10 +29,22 @@ impl Socket {
namespace,
engine_sid,
ack_id: AtomicU64::new(0),
user_id: OnceLock::new(),
tx,
}
}
/// Set the authenticated user ID after JWT verification.
/// Safe to call once; subsequent calls are ignored.
pub fn set_user_id(&self, id: Uuid) {
let _ = self.user_id.set(id);
}
/// Get the authenticated user ID, if set.
pub fn user_id(&self) -> Option<Uuid> {
self.user_id.get().copied()
}
pub fn next_ack_id(&self) -> u64 {
self.ack_id.fetch_add(1, Ordering::SeqCst)
}
@@ -36,7 +53,11 @@ impl Socket {
self.tx.try_send(packet.clone())
}
pub fn emit(&self, event: impl Into<String>, data: serde_json::Value) -> Result<(), mpsc::error::TrySendError<Packet>> {
pub fn emit(
&self,
event: impl Into<String>,
data: serde_json::Value,
) -> Result<(), mpsc::error::TrySendError<Packet>> {
let packet = Packet::event(
&self.namespace,
serde_json::json!([event.into(), data]),
@@ -65,7 +86,11 @@ impl Socket {
self.send_packet(&packet)
}
pub fn send_ack(&self, id: u64, data: serde_json::Value) -> Result<(), mpsc::error::TrySendError<Packet>> {
pub fn send_ack(
&self,
id: u64,
data: serde_json::Value,
) -> Result<(), mpsc::error::TrySendError<Packet>> {
let packet = Packet::ack(&self.namespace, data, id);
self.send_packet(&packet)
}