Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

[rust]: fix multi thread test bugs

appflowy635f6b860787
diff --git a/rust-lib/dart-ffi/src/lib.rs b/rust-lib/dart-ffi/src/lib.rs
index d32a01f2c7..b0aa36a45c 100644
--- a/rust-lib/dart-ffi/src/lib.rs
+++ b/rust-lib/dart-ffi/src/lib.rs
@@ -25,7 +25,7 @@ pub extern "C" fn init_sdk(path: *mut c_char) -> i64 {
let path: &str = c_str.to_str().unwrap();
let server_config = ServerConfig::default();
- let config = FlowySDKConfig::new(path, server_config).log_filter("debug");
+ let config = FlowySDKConfig::new(path, server_config, "AppFlowy").log_filter("debug");
*FLOWY_SDK.write() = Some(Arc::new(FlowySDK::new(config)));
return 1;
diff --git a/rust-lib/flowy-sdk/src/lib.rs b/rust-lib/flowy-sdk/src/lib.rs
index 70c5c1f47d..9caced7d2d 100644
--- a/rust-lib/flowy-sdk/src/lib.rs
+++ b/rust-lib/flowy-sdk/src/lib.rs
@@ -20,14 +20,16 @@ static INIT_LOG: AtomicBool = AtomicBool::new(false);
#[derive(Debug, Clone)]
pub struct FlowySDKConfig {
+ name: String,
root: String,
log_filter: String,
server_config: ServerConfig,
}
impl FlowySDKConfig {
- pub fn new(root: &str, server_config: ServerConfig) -> Self {
+ pub fn new(root: &str, server_config: ServerConfig, name: &str) -> Self {
FlowySDKConfig {
+ name: name.to_owned(),
root: root.to_owned(),
log_filter: crate_log_filter(None),
server_config,
@@ -70,9 +72,10 @@ impl FlowySDK {
init_kv(&config.root);
tracing::debug!("🔥 {:?}", config);
+ let session_cache_key = format!("{}_session_cache", &config.name);
let user_session = Arc::new(
UserSessionBuilder::new()
- .root_dir(&config.root, &config.server_config)
+ .root_dir(&config.root, &config.server_config, &session_cache_key)
.build(),
);
let flowy_document = mk_document_module(user_session.clone(), &config.server_config);
diff --git a/rust-lib/flowy-test/src/lib.rs b/rust-lib/flowy-test/src/lib.rs
index 883880349b..d738ad0f8e 100644
--- a/rust-lib/flowy-test/src/lib.rs
+++ b/rust-lib/flowy-test/src/lib.rs
@@ -3,6 +3,7 @@ mod helper;
pub mod workspace;
use crate::helper::*;
+use flowy_infra::uuid;
use flowy_net::config::ServerConfig;
use flowy_sdk::{FlowySDK, FlowySDKConfig};
use flowy_user::entities::UserProfile;
@@ -38,7 +39,7 @@ impl FlowyTest {
}
pub fn setup_with(server_config: ServerConfig) -> Self {
- let config = FlowySDKConfig::new(&root_dir(), server_config).log_filter("debug");
+ let config = FlowySDKConfig::new(&root_dir(), server_config, &uuid().to_string()).log_filter("debug");
let sdk = FlowySDK::new(config);
Self { sdk }
}
diff --git a/rust-lib/flowy-user/src/services/user/builder.rs b/rust-lib/flowy-user/src/services/user/builder.rs
index d3b199932b..e6e265e7cb 100644
--- a/rust-lib/flowy-user/src/services/user/builder.rs
+++ b/rust-lib/flowy-user/src/services/user/builder.rs
@@ -8,8 +8,8 @@ pub struct UserSessionBuilder {
impl UserSessionBuilder {
pub fn new() -> Self { Self { config: None } }
- pub fn root_dir(mut self, dir: &str, server_config: &ServerConfig) -> Self {
- self.config = Some(UserSessionConfig::new(dir, server_config));
+ pub fn root_dir(mut self, dir: &str, server_config: &ServerConfig, session_cache_key: &str) -> Self {
+ self.config = Some(UserSessionConfig::new(dir, server_config, session_cache_key));
self
}
diff --git a/rust-lib/flowy-user/src/services/user/user_session.rs b/rust-lib/flowy-user/src/services/user/user_session.rs
index 28d25f6b8c..f4e4bbb42a 100644
--- a/rust-lib/flowy-user/src/services/user/user_session.rs
+++ b/rust-lib/flowy-user/src/services/user/user_session.rs
@@ -36,13 +36,15 @@ pub enum UserStatus {
pub struct UserSessionConfig {
root_dir: String,
server_config: ServerConfig,
+ session_cache_key: String,
}
impl UserSessionConfig {
- pub fn new(root_dir: &str, server_config: &ServerConfig) -> Self {
+ pub fn new(root_dir: &str, server_config: &ServerConfig, session_cache_key: &str) -> Self {
Self {
root_dir: root_dir.to_owned(),
server_config: server_config.clone(),
+ session_cache_key: session_cache_key.to_owned(),
}
}
}
@@ -263,8 +265,10 @@ impl UserSession {
fn set_session(&self, session: Option<Session>) -> Result<(), UserError> {
tracing::debug!("Set user session: {:?}", session);
match &session {
- None => KV::remove(SESSION_CACHE_KEY).map_err(|e| UserError::new(ErrorCode::InternalError, &e))?,
- Some(session) => KV::set_str(SESSION_CACHE_KEY, session.clone().into()),
+ None => {
+ KV::remove(&self.config.session_cache_key).map_err(|e| UserError::new(ErrorCode::InternalError, &e))?
+ },
+ Some(session) => KV::set_str(&self.config.session_cache_key, session.clone().into()),
}
*self.session.write() = session;
Ok(())
@@ -273,7 +277,7 @@ impl UserSession {
fn get_session(&self) -> Result<Session, UserError> {
let mut session = { (*self.session.read()).clone() };
if session.is_none() {
- match KV::get_str(SESSION_CACHE_KEY) {
+ match KV::get_str(&self.config.session_cache_key) {
None => {},
Some(s) => {
session = Some(Session::from(s));
@@ -350,8 +354,6 @@ impl UserDatabaseConnection for UserSession {
fn get_connection(&self) -> Result<DBConnection, String> { self.db_connection().map_err(|e| format!("{:?}", e)) }
}
-const SESSION_CACHE_KEY: &str = "session_cache_key";
-
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
struct Session {
user_id: String,
diff --git a/rust-lib/flowy-workspace-infra/src/entities/share/export.rs b/rust-lib/flowy-workspace-infra/src/entities/share/export.rs
index 312558fc41..e82b59d674 100644
--- a/rust-lib/flowy-workspace-infra/src/entities/share/export.rs
+++ b/rust-lib/flowy-workspace-infra/src/entities/share/export.rs
@@ -34,7 +34,7 @@ pub struct ExportRequest {
pub export_type: ExportType,
}
-#[derive(Default)]
+#[derive(Default, Debug)]
pub struct ExportParams {
pub doc_id: String,
pub export_type: ExportType,
diff --git a/rust-lib/flowy-workspace/src/services/view_controller.rs b/rust-lib/flowy-workspace/src/services/view_controller.rs
index b4438b1069..433bc086ee 100644
--- a/rust-lib/flowy-workspace/src/services/view_controller.rs
+++ b/rust-lib/flowy-workspace/src/services/view_controller.rs
@@ -139,7 +139,7 @@ impl ViewController {
Ok(())
}
- #[tracing::instrument(level = "debug", skip(self, params), err)]
+ #[tracing::instrument(level = "debug", skip(self), err)]
pub(crate) async fn export_doc(&self, _params: ExportParams) -> Result<ExportData, WorkspaceError> {
unimplemented!()
}
diff --git a/scripts/makefile/env.toml b/scripts/makefile/env.toml
index fcda5ea4ef..8cdd7bb430 100644
--- a/scripts/makefile/env.toml
+++ b/scripts/makefile/env.toml
@@ -1,5 +1,5 @@
[tasks.flowy_dev]
-run_task = { name = ["install_targets","install_diesel", "install_protobuf", "install_tools", "install_flutter"] }
+run_task = { name = ["install_targets","install_diesel", "install_protobuf"] }
[tasks.install_diesel]
script = """