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
+7 -2
View File
@@ -33,7 +33,12 @@ fn now_millis() -> u64 {
#[async_trait]
impl SessionStoreTrait for InMemorySessionStore {
async fn create(&self, sid: &str, transport: &str, server_id: &str) -> Result<(), SessionError> {
async fn create(
&self,
sid: &str,
transport: &str,
server_id: &str,
) -> Result<(), SessionError> {
let info = SessionInfo {
sid: sid.to_string(),
transport: transport.to_string(),
@@ -85,4 +90,4 @@ impl SessionStoreTrait for InMemorySessionStore {
async fn exists(&self, sid: &str) -> Result<bool, SessionError> {
Ok(self.sessions.contains_key(sid))
}
}
}
+3 -2
View File
@@ -28,7 +28,8 @@ pub struct SessionInfo {
#[async_trait]
pub trait SessionStoreTrait: Send + Sync + 'static {
async fn create(&self, sid: &str, transport: &str, server_id: &str) -> Result<(), SessionError>;
async fn create(&self, sid: &str, transport: &str, server_id: &str)
-> Result<(), SessionError>;
async fn get(&self, sid: &str) -> Result<Option<SessionInfo>, SessionError>;
async fn set_state(&self, sid: &str, state: &str) -> Result<(), SessionError>;
async fn set_transport(&self, sid: &str, transport: &str) -> Result<(), SessionError>;
@@ -38,4 +39,4 @@ pub trait SessionStoreTrait: Send + Sync + 'static {
}
pub use memory::InMemorySessionStore;
pub use redis::RedisSessionStore;
pub use redis::RedisSessionStore;
+19 -6
View File
@@ -36,7 +36,12 @@ impl RedisSessionStore {
#[async_trait]
impl SessionStoreTrait for RedisSessionStore {
async fn create(&self, sid: &str, transport: &str, server_id: &str) -> Result<(), SessionError> {
async fn create(
&self,
sid: &str,
transport: &str,
server_id: &str,
) -> Result<(), SessionError> {
let key = self.key(sid);
let now = now_millis();
@@ -67,7 +72,8 @@ impl SessionStoreTrait for RedisSessionStore {
// Use hgetall directly — if the key doesn't exist Redis returns an empty map.
// This avoids the TOCTOU race between EXISTS and HGETALL.
let values: std::collections::HashMap<String, String> = self.client
let values: std::collections::HashMap<String, String> = self
.client
.hgetall::<std::collections::HashMap<String, String>, _>(&key)
.await
.map_err(|e| SessionError::Redis(e.to_string()))?;
@@ -81,8 +87,14 @@ impl SessionStoreTrait for RedisSessionStore {
transport: values.get("transport").cloned().unwrap_or_default(),
state: values.get("state").cloned().unwrap_or_default(),
server_id: values.get("server_id").cloned().unwrap_or_default(),
created_at: values.get("created_at").and_then(|v| v.parse::<u64>().ok()).unwrap_or(0),
last_ping: values.get("last_ping").and_then(|v| v.parse::<u64>().ok()).unwrap_or(0),
created_at: values
.get("created_at")
.and_then(|v| v.parse::<u64>().ok())
.unwrap_or(0),
last_ping: values
.get("last_ping")
.and_then(|v| v.parse::<u64>().ok())
.unwrap_or(0),
};
Ok(Some(info))
@@ -154,11 +166,12 @@ impl SessionStoreTrait for RedisSessionStore {
async fn exists(&self, sid: &str) -> Result<bool, SessionError> {
let key = self.key(sid);
let exists: bool = self.client
let exists: bool = self
.client
.exists::<bool, _>(&key)
.await
.map_err(|e| SessionError::Redis(e.to_string()))?;
Ok(exists)
}
}
}