[rust]: rename backend test code

This commit is contained in:
appflowy 2021-11-19 13:42:53 +08:00
parent 7bd2773cf2
commit 80d1b3072d
9 changed files with 47 additions and 47 deletions

View File

@ -243,7 +243,6 @@ fn send_acked_msg(socket: &Socket, revision: &Revision) -> Result<(), ServerErro
fn mk_acked_message(revision: &Revision) -> WsMessageAdaptor {
// let mut wtr = vec![];
// let _ = wtr.write_i64::<BigEndian>(revision.rev_id);
let mut rev_id = RevId::new();
rev_id.set_value(revision.rev_id);
let data = rev_id.write_to_bytes().unwrap();

View File

@ -1,4 +1,4 @@
use crate::helper::{spawn_user_server, TestUserServer};
use crate::util::helper::{spawn_user_server, TestUserServer};
use flowy_net::errors::ErrorCode;
use flowy_user_infra::entities::{SignInParams, SignUpParams, SignUpResponse, UpdateUserParams};

View File

@ -1,4 +1,4 @@
use crate::helper::ViewTest;
use crate::util::helper::ViewTest;
use flowy_document_infra::entities::doc::DocIdentifier;
use flowy_workspace_infra::entities::view::ViewIdentifiers;

View File

@ -1,4 +1,4 @@
use crate::helper::*;
use crate::util::helper::*;
use flowy_workspace_infra::entities::{
app::{AppIdentifier, UpdateAppParams},
trash::{TrashIdentifier, TrashIdentifiers, TrashType},

View File

@ -20,10 +20,10 @@ use flowy_ot::core::{Attribute, Interval};
async fn delta_sync_while_editing() {
let test = DocumentTest::new().await;
test.run_scripts(vec![
DocScript::ConnectWs,
DocScript::OpenDoc,
DocScript::InsertText(0, "abc"),
DocScript::InsertText(3, "123"),
DocScript::ClientConnectWs,
DocScript::ClientOpenDoc,
DocScript::ClientInsertText(0, "abc"),
DocScript::ClientInsertText(3, "123"),
DocScript::AssertClient(r#"[{"insert":"abc123\n"}]"#),
DocScript::AssertServer(r#"[{"insert":"abc123\n"}]"#, 2),
])
@ -34,12 +34,12 @@ async fn delta_sync_while_editing() {
async fn delta_sync_multi_revs() {
let test = DocumentTest::new().await;
test.run_scripts(vec![
DocScript::ConnectWs,
DocScript::OpenDoc,
DocScript::InsertText(0, "abc"),
DocScript::InsertText(3, "123"),
DocScript::InsertText(6, "efg"),
DocScript::InsertText(9, "456"),
DocScript::ClientConnectWs,
DocScript::ClientOpenDoc,
DocScript::ClientInsertText(0, "abc"),
DocScript::ClientInsertText(3, "123"),
DocScript::ClientInsertText(6, "efg"),
DocScript::ClientInsertText(9, "456"),
])
.await;
}
@ -48,14 +48,14 @@ async fn delta_sync_multi_revs() {
async fn delta_sync_while_editing_with_attribute() {
let test = DocumentTest::new().await;
test.run_scripts(vec![
DocScript::ConnectWs,
DocScript::OpenDoc,
DocScript::InsertText(0, "abc"),
DocScript::FormatText(Interval::new(0, 3), Attribute::Bold(true)),
DocScript::ClientConnectWs,
DocScript::ClientOpenDoc,
DocScript::ClientInsertText(0, "abc"),
DocScript::ClientFormatText(Interval::new(0, 3), Attribute::Bold(true)),
DocScript::AssertClient(r#"[{"insert":"abc","attributes":{"bold":true}},{"insert":"\n"}]"#),
DocScript::AssertServer(r#"[{"insert":"abc","attributes":{"bold":true}},{"insert":"\n"}]"#, 2),
DocScript::InsertText(3, "efg"),
DocScript::FormatText(Interval::new(3, 5), Attribute::Italic(true)),
DocScript::ClientInsertText(3, "efg"),
DocScript::ClientFormatText(Interval::new(3, 5), Attribute::Italic(true)),
DocScript::AssertClient(r#"[{"insert":"abc","attributes":{"bold":true}},{"insert":"ef","attributes":{"bold":true,"italic":true}},{"insert":"g","attributes":{"bold":true}},{"insert":"\n"}]"#),
DocScript::AssertServer(r#"[{"insert":"abc","attributes":{"bold":true}},{"insert":"ef","attributes":{"bold":true,"italic":true}},{"insert":"g","attributes":{"bold":true}},{"insert":"\n"}]"#, 4),
])
@ -84,8 +84,8 @@ async fn delta_sync_with_http_request() {
let json = document.to_json();
test.run_scripts(vec![
DocScript::SetServerDocument(json, 3),
DocScript::OpenDoc,
DocScript::ServerSaveDocument(json, 3),
DocScript::ClientOpenDoc,
DocScript::AssertClient(r#"[{"insert":"123456\n"}]"#),
DocScript::AssertServer(r#"[{"insert":"123456\n"}]"#, 3),
])
@ -100,9 +100,9 @@ async fn delta_sync_with_server_push_delta() {
let json = document.to_json();
test.run_scripts(vec![
DocScript::OpenDoc,
DocScript::SetServerDocument(json, 3),
DocScript::ConnectWs,
DocScript::ClientOpenDoc,
DocScript::ServerSaveDocument(json, 3),
DocScript::ClientConnectWs,
DocScript::AssertClient(r#"[{"insert":"\n123\n"}]"#),
])
.await;
@ -147,10 +147,10 @@ async fn delta_sync_while_local_rev_less_than_server_rev() {
let json = document.to_json();
test.run_scripts(vec![
DocScript::OpenDoc,
DocScript::SetServerDocument(json, 3),
DocScript::InsertText(0, "abc"),
DocScript::ConnectWs,
DocScript::ClientOpenDoc,
DocScript::ServerSaveDocument(json, 3),
DocScript::ClientInsertText(0, "abc"),
DocScript::ClientConnectWs,
DocScript::AssertClient(r#"[{"insert":"abc\n123\n"}]"#),
DocScript::AssertServer(r#"[{"insert":"abc\n123\n"}]"#, 4),
])
@ -190,14 +190,14 @@ async fn delta_sync_while_local_rev_greater_than_server_rev() {
let json = document.to_json();
test.run_scripts(vec![
DocScript::SetServerDocument(json, 1),
DocScript::OpenDoc,
DocScript::ServerSaveDocument(json, 1),
DocScript::ClientOpenDoc,
DocScript::AssertClient(r#"[{"insert":"123\n"}]"#),
DocScript::InsertText(3, "abc"),
DocScript::InsertText(6, "efg"),
DocScript::ConnectWs,
DocScript::ClientInsertText(3, "abc"),
DocScript::ClientInsertText(6, "efg"),
DocScript::ClientConnectWs,
DocScript::AssertClient(r#"[{"insert":"123abcefg\n"}]"#),
DocScript::AssertServer(r#"[{"insert":"123abcefg\n"}]"#, 3),
// DocScript::AssertServer(r#"[{"insert":"123abcefg\n"}]"#, 3),
])
.await;
}

View File

@ -9,7 +9,7 @@ use sqlx::PgPool;
use std::sync::Arc;
use tokio::time::{sleep, Duration};
// use crate::helper::*;
use crate::helper::{spawn_server, TestServer};
use crate::util::helper::{spawn_server, TestServer};
use flowy_document_infra::{entities::doc::DocIdentifier, protobuf::UpdateDocParams};
use flowy_ot::core::{Attribute, Delta, Interval};
use parking_lot::RwLock;
@ -20,13 +20,13 @@ pub struct DocumentTest {
}
#[derive(Clone)]
pub enum DocScript {
ConnectWs,
InsertText(usize, &'static str),
FormatText(Interval, Attribute),
ClientConnectWs,
ClientInsertText(usize, &'static str),
ClientFormatText(Interval, Attribute),
ClientOpenDoc,
AssertClient(&'static str),
AssertServer(&'static str, i64),
SetServerDocument(String, i64), // delta_json, rev_id
OpenDoc,
ServerSaveDocument(String, i64), // delta_json, rev_id
}
impl DocumentTest {
@ -95,19 +95,19 @@ async fn run_scripts(context: Arc<RwLock<ScriptContext>>, scripts: Vec<DocScript
let fut = async move {
let doc_id = context.read().doc_id.clone();
match script {
DocScript::ConnectWs => {
DocScript::ClientConnectWs => {
// sleep(Duration::from_millis(300)).await;
let user_session = context.read().client_user_session.clone();
let token = user_session.token().unwrap();
let _ = user_session.start_ws_connection(&token).await.unwrap();
},
DocScript::OpenDoc => {
DocScript::ClientOpenDoc => {
context.write().open_doc().await;
},
DocScript::InsertText(index, s) => {
DocScript::ClientInsertText(index, s) => {
context.read().client_edit_context().insert(index, s).await.unwrap();
},
DocScript::FormatText(interval, attribute) => {
DocScript::ClientFormatText(interval, attribute) => {
context
.read()
.client_edit_context()
@ -129,7 +129,7 @@ async fn run_scripts(context: Arc<RwLock<ScriptContext>>, scripts: Vec<DocScript
let json = edit_doc.document_json().await.unwrap();
assert_eq(s, &json);
},
DocScript::SetServerDocument(json, rev_id) => {
DocScript::ServerSaveDocument(json, rev_id) => {
let pg_pool = context.read().server_pg_pool.clone();
save_doc(&doc_id, json, rev_id, pg_pool).await;
},

View File

@ -1,3 +1,3 @@
mod api;
mod document;
pub mod helper;
pub mod util;

View File

@ -0,0 +1 @@
pub mod helper;