feat: enable dispatch event using single thread (#3828)

* refactor: lib dispatch

* chore: type def

* chore: type def

* fix: local set spawn

* chore: replace tokio spawn

* chore: update log

* chore: boxed event

* chore: tauri lock
This commit is contained in:
Nathan.fooo
2023-10-30 12:35:06 +08:00
committed by GitHub
parent 7f4e7e6aa0
commit e08a1a6974
67 changed files with 822 additions and 554 deletions

View File

@ -6,7 +6,7 @@ use crate::util::{generate_test_email, get_af_cloud_config};
#[tokio::test]
async fn af_cloud_sign_up_test() {
if get_af_cloud_config().is_some() {
let test = EventIntegrationTest::new();
let test = EventIntegrationTest::new().await;
let email = generate_test_email();
let user = test.af_cloud_sign_in_with_email(&email).await.unwrap();
assert_eq!(user.email, email);
@ -16,7 +16,7 @@ async fn af_cloud_sign_up_test() {
#[tokio::test]
async fn af_cloud_update_user_metadata() {
if get_af_cloud_config().is_some() {
let test = EventIntegrationTest::new();
let test = EventIntegrationTest::new().await;
let user = test.af_cloud_sign_up().await;
let old_profile = test.get_user_profile().await.unwrap();

View File

@ -5,10 +5,10 @@ use crate::util::get_af_cloud_config;
#[tokio::test]
async fn af_cloud_add_workspace_member_test() {
if get_af_cloud_config().is_some() {
let test_1 = EventIntegrationTest::new();
let test_1 = EventIntegrationTest::new().await;
let user_1 = test_1.af_cloud_sign_up().await;
let test_2 = EventIntegrationTest::new();
let test_2 = EventIntegrationTest::new().await;
let user_2 = test_2.af_cloud_sign_up().await;
let members = test_1.get_workspace_members(&user_1.workspace_id).await;
@ -29,10 +29,10 @@ async fn af_cloud_add_workspace_member_test() {
#[tokio::test]
async fn af_cloud_delete_workspace_member_test() {
if get_af_cloud_config().is_some() {
let test_1 = EventIntegrationTest::new();
let test_1 = EventIntegrationTest::new().await;
let user_1 = test_1.af_cloud_sign_up().await;
let test_2 = EventIntegrationTest::new();
let test_2 = EventIntegrationTest::new().await;
let user_2 = test_2.af_cloud_sign_up().await;
test_1

View File

@ -9,7 +9,7 @@ use crate::user::local_test::helper::*;
#[tokio::test]
async fn sign_up_with_invalid_email() {
for email in invalid_email_test_case() {
let sdk = EventIntegrationTest::new();
let sdk = EventIntegrationTest::new().await;
let request = SignUpPayloadPB {
email: email.to_string(),
name: valid_name(),
@ -33,7 +33,7 @@ async fn sign_up_with_invalid_email() {
}
#[tokio::test]
async fn sign_up_with_long_password() {
let sdk = EventIntegrationTest::new();
let sdk = EventIntegrationTest::new().await;
let request = SignUpPayloadPB {
email: unique_email(),
name: valid_name(),
@ -58,7 +58,7 @@ async fn sign_up_with_long_password() {
#[tokio::test]
async fn sign_in_with_invalid_email() {
for email in invalid_email_test_case() {
let sdk = EventIntegrationTest::new();
let sdk = EventIntegrationTest::new().await;
let request = SignInPayloadPB {
email: email.to_string(),
password: login_password(),
@ -84,7 +84,7 @@ async fn sign_in_with_invalid_email() {
#[tokio::test]
async fn sign_in_with_invalid_password() {
for password in invalid_password_test_case() {
let sdk = EventIntegrationTest::new();
let sdk = EventIntegrationTest::new().await;
let request = SignInPayloadPB {
email: unique_email(),

View File

@ -6,8 +6,8 @@ use flowy_user::entities::{ReminderPB, RepeatedReminderPB};
use flowy_user::event_map::UserEvent::*;
#[tokio::test]
async fn user_update_with_name() {
let sdk = EventIntegrationTest::new();
async fn user_update_with_reminder() {
let sdk = EventIntegrationTest::new().await;
let _ = sdk.sign_up_as_guest().await;
let mut meta = HashMap::new();
meta.insert("object_id".to_string(), "".to_string());

View File

@ -10,7 +10,7 @@ use crate::user::local_test::helper::*;
#[tokio::test]
async fn user_profile_get_failed() {
let sdk = EventIntegrationTest::new();
let sdk = EventIntegrationTest::new().await;
let result = EventBuilder::new(sdk)
.event(GetUserProfile)
.async_send()
@ -21,11 +21,12 @@ async fn user_profile_get_failed() {
#[tokio::test]
async fn anon_user_profile_get() {
let test = EventIntegrationTest::new();
let test = EventIntegrationTest::new().await;
let user_profile = test.init_anon_user().await;
let user = EventBuilder::new(test.clone())
.event(GetUserProfile)
.sync_send()
.async_send()
.await
.parse::<UserProfilePB>();
assert_eq!(user_profile.id, user.id);
assert_eq!(user_profile.openai_key, user.openai_key);
@ -36,18 +37,20 @@ async fn anon_user_profile_get() {
#[tokio::test]
async fn user_update_with_name() {
let sdk = EventIntegrationTest::new();
let sdk = EventIntegrationTest::new().await;
let user = sdk.init_anon_user().await;
let new_name = "hello_world".to_owned();
let request = UpdateUserProfilePayloadPB::new(user.id).name(&new_name);
let _ = EventBuilder::new(sdk.clone())
.event(UpdateUserProfile)
.payload(request)
.sync_send();
.async_send()
.await;
let user_profile = EventBuilder::new(sdk.clone())
.event(GetUserProfile)
.sync_send()
.async_send()
.await
.parse::<UserProfilePB>();
assert_eq!(user_profile.name, new_name,);
@ -55,7 +58,7 @@ async fn user_update_with_name() {
#[tokio::test]
async fn user_update_with_ai_key() {
let sdk = EventIntegrationTest::new();
let sdk = EventIntegrationTest::new().await;
let user = sdk.init_anon_user().await;
let openai_key = "openai_key".to_owned();
let stability_ai_key = "stability_ai_key".to_owned();
@ -65,11 +68,13 @@ async fn user_update_with_ai_key() {
let _ = EventBuilder::new(sdk.clone())
.event(UpdateUserProfile)
.payload(request)
.sync_send();
.async_send()
.await;
let user_profile = EventBuilder::new(sdk.clone())
.event(GetUserProfile)
.sync_send()
.async_send()
.await
.parse::<UserProfilePB>();
assert_eq!(user_profile.openai_key, openai_key,);
@ -78,17 +83,19 @@ async fn user_update_with_ai_key() {
#[tokio::test]
async fn anon_user_update_with_email() {
let sdk = EventIntegrationTest::new();
let sdk = EventIntegrationTest::new().await;
let user = sdk.init_anon_user().await;
let new_email = format!("{}@gmail.com", nanoid!(6));
let request = UpdateUserProfilePayloadPB::new(user.id).email(&new_email);
let _ = EventBuilder::new(sdk.clone())
.event(UpdateUserProfile)
.payload(request)
.sync_send();
.async_send()
.await;
let user_profile = EventBuilder::new(sdk.clone())
.event(GetUserProfile)
.sync_send()
.async_send()
.await
.parse::<UserProfilePB>();
// When the user is anonymous, the email is empty no matter what you set
@ -97,7 +104,7 @@ async fn anon_user_update_with_email() {
#[tokio::test]
async fn user_update_with_invalid_email() {
let test = EventIntegrationTest::new();
let test = EventIntegrationTest::new().await;
let user = test.init_anon_user().await;
for email in invalid_email_test_case() {
let request = UpdateUserProfilePayloadPB::new(user.id).email(&email);
@ -105,7 +112,8 @@ async fn user_update_with_invalid_email() {
EventBuilder::new(test.clone())
.event(UpdateUserProfile)
.payload(request)
.sync_send()
.async_send()
.await
.error()
.unwrap()
.code,
@ -116,7 +124,7 @@ async fn user_update_with_invalid_email() {
#[tokio::test]
async fn user_update_with_invalid_password() {
let test = EventIntegrationTest::new();
let test = EventIntegrationTest::new().await;
let user = test.init_anon_user().await;
for password in invalid_password_test_case() {
let request = UpdateUserProfilePayloadPB::new(user.id).password(&password);
@ -133,13 +141,14 @@ async fn user_update_with_invalid_password() {
#[tokio::test]
async fn user_update_with_invalid_name() {
let test = EventIntegrationTest::new();
let test = EventIntegrationTest::new().await;
let user = test.init_anon_user().await;
let request = UpdateUserProfilePayloadPB::new(user.id).name("");
assert!(EventBuilder::new(test.clone())
.event(UpdateUserProfile)
.payload(request)
.sync_send()
.async_send()
.await
.error()
.is_some())
}

View File

@ -11,7 +11,8 @@ async fn migrate_historical_empty_document_test() {
"historical_empty_document",
)
.unwrap();
let test = EventIntegrationTest::new_with_user_data_path(user_db_path, DEFAULT_NAME.to_string());
let test =
EventIntegrationTest::new_with_user_data_path(user_db_path, DEFAULT_NAME.to_string()).await;
let views = test.get_all_workspace_views().await;
assert_eq!(views.len(), 3);

View File

@ -11,7 +11,8 @@ async fn migrate_020_historical_empty_document_test() {
"020_historical_user_data",
)
.unwrap();
let test = EventIntegrationTest::new_with_user_data_path(user_db_path, DEFAULT_NAME.to_string());
let test =
EventIntegrationTest::new_with_user_data_path(user_db_path, DEFAULT_NAME.to_string()).await;
let mut views = test.get_all_workspace_views().await;
assert_eq!(views.len(), 1);

View File

@ -13,7 +13,7 @@ use event_integration::event_builder::EventBuilder;
use event_integration::EventIntegrationTest;
use flowy_core::DEFAULT_NAME;
use flowy_encrypt::decrypt_text;
use flowy_server::supabase::define::{USER_EMAIL, USER_UUID};
use flowy_server::supabase::define::{USER_DEVICE_ID, USER_EMAIL, USER_UUID};
use flowy_user::entities::{AuthTypePB, OauthSignInPB, UpdateUserProfilePayloadPB, UserProfilePB};
use flowy_user::errors::ErrorCode;
use flowy_user::event_map::UserEvent::*;
@ -23,13 +23,14 @@ use crate::util::*;
#[tokio::test]
async fn third_party_sign_up_test() {
if get_supabase_config().is_some() {
let test = EventIntegrationTest::new();
let test = EventIntegrationTest::new().await;
let mut map = HashMap::new();
map.insert(USER_UUID.to_string(), uuid::Uuid::new_v4().to_string());
map.insert(
USER_EMAIL.to_string(),
format!("{}@appflowy.io", nanoid!(6)),
);
map.insert(USER_DEVICE_ID.to_string(), uuid::Uuid::new_v4().to_string());
let payload = OauthSignInPB {
map,
auth_type: AuthTypePB::Supabase,
@ -48,7 +49,7 @@ async fn third_party_sign_up_test() {
#[tokio::test]
async fn third_party_sign_up_with_encrypt_test() {
if get_supabase_config().is_some() {
let test = EventIntegrationTest::new();
let test = EventIntegrationTest::new().await;
test.supabase_party_sign_up().await;
let user_profile = test.get_user_profile().await.unwrap();
assert!(user_profile.encryption_sign.is_empty());
@ -65,11 +66,12 @@ async fn third_party_sign_up_with_encrypt_test() {
#[tokio::test]
async fn third_party_sign_up_with_duplicated_uuid() {
if get_supabase_config().is_some() {
let test = EventIntegrationTest::new();
let test = EventIntegrationTest::new().await;
let email = format!("{}@appflowy.io", nanoid!(6));
let mut map = HashMap::new();
map.insert(USER_UUID.to_string(), uuid::Uuid::new_v4().to_string());
map.insert(USER_EMAIL.to_string(), email.clone());
map.insert(USER_DEVICE_ID.to_string(), uuid::Uuid::new_v4().to_string());
let response_1 = EventBuilder::new(test.clone())
.event(OauthSignIn)
@ -98,7 +100,7 @@ async fn third_party_sign_up_with_duplicated_uuid() {
#[tokio::test]
async fn third_party_sign_up_with_duplicated_email() {
if get_supabase_config().is_some() {
let test = EventIntegrationTest::new();
let test = EventIntegrationTest::new().await;
let email = format!("{}@appflowy.io", nanoid!(6));
test
.supabase_sign_up_with_uuid(&uuid::Uuid::new_v4().to_string(), Some(email.clone()))
@ -138,7 +140,6 @@ async fn sign_up_as_guest_and_then_update_to_new_cloud_user_test() {
assert_eq!(old_workspace.views.len(), new_workspace.views.len());
for (index, view) in old_views.iter().enumerate() {
assert_eq!(view.name, new_views[index].name);
assert_eq!(view.id, new_views[index].id);
assert_eq!(view.layout, new_views[index].layout);
assert_eq!(view.create_time, new_views[index].create_time);
}
@ -196,7 +197,7 @@ async fn sign_up_as_guest_and_then_update_to_existing_cloud_user_test() {
#[tokio::test]
async fn get_user_profile_test() {
if let Some(test) = FlowySupabaseTest::new() {
if let Some(test) = FlowySupabaseTest::new().await {
let uuid = uuid::Uuid::new_v4().to_string();
test.supabase_sign_up_with_uuid(&uuid, None).await.unwrap();
@ -207,7 +208,7 @@ async fn get_user_profile_test() {
#[tokio::test]
async fn update_user_profile_test() {
if let Some(test) = FlowySupabaseTest::new() {
if let Some(test) = FlowySupabaseTest::new().await {
let uuid = uuid::Uuid::new_v4().to_string();
let profile = test.supabase_sign_up_with_uuid(&uuid, None).await.unwrap();
test
@ -221,7 +222,7 @@ async fn update_user_profile_test() {
#[tokio::test]
async fn update_user_profile_with_existing_email_test() {
if let Some(test) = FlowySupabaseTest::new() {
if let Some(test) = FlowySupabaseTest::new().await {
let email = format!("{}@appflowy.io", nanoid!(6));
let _ = test
.supabase_sign_up_with_uuid(&uuid::Uuid::new_v4().to_string(), Some(email.clone()))
@ -249,7 +250,7 @@ async fn update_user_profile_with_existing_email_test() {
#[tokio::test]
async fn migrate_anon_document_on_cloud_signup() {
if get_supabase_config().is_some() {
let test = EventIntegrationTest::new();
let test = EventIntegrationTest::new().await;
let user_profile = test.sign_up_as_guest().await.user_profile;
let view = test
@ -295,7 +296,7 @@ async fn migrate_anon_data_on_cloud_signup() {
)
.unwrap();
let test =
EventIntegrationTest::new_with_user_data_path(user_db_path, DEFAULT_NAME.to_string());
EventIntegrationTest::new_with_user_data_path(user_db_path, DEFAULT_NAME.to_string()).await;
let user_profile = test.supabase_party_sign_up().await;
// Get the folder data from remote

View File

@ -12,7 +12,7 @@ use crate::util::*;
#[tokio::test]
async fn initial_workspace_test() {
if get_supabase_config().is_some() {
let test = EventIntegrationTest::new();
let test = EventIntegrationTest::new().await;
let mut map = HashMap::new();
map.insert(USER_UUID.to_string(), uuid::Uuid::new_v4().to_string());
map.insert(