2022-11-02 17:15:27 +08:00
|
|
|
use crate::revision_test::script::{RevisionScript::*, RevisionTest};
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn revision_sync_test() {
|
2023-02-13 09:29:49 +08:00
|
|
|
let test = RevisionTest::new().await;
|
|
|
|
let rev_id = 1;
|
|
|
|
test
|
|
|
|
.run_script(AddLocalRevision {
|
|
|
|
content: "123".to_string(),
|
2022-11-02 17:15:27 +08:00
|
|
|
})
|
|
|
|
.await;
|
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
test
|
|
|
|
.run_script(AssertNextSyncRevisionId {
|
|
|
|
rev_id: Some(rev_id),
|
|
|
|
})
|
|
|
|
.await;
|
|
|
|
test.run_script(AckRevision { rev_id }).await;
|
|
|
|
test
|
|
|
|
.run_script(AssertNextSyncRevisionId { rev_id: None })
|
|
|
|
.await;
|
2022-11-02 17:15:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
2022-11-07 17:30:24 +08:00
|
|
|
async fn revision_compress_2_revisions_with_2_threshold_test() {
|
2023-02-13 09:29:49 +08:00
|
|
|
let test = RevisionTest::new_with_configuration(2).await;
|
|
|
|
test
|
|
|
|
.run_script(AddLocalRevision2 {
|
|
|
|
content: "123".to_string(),
|
2022-11-02 17:15:27 +08:00
|
|
|
})
|
|
|
|
.await;
|
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
test
|
|
|
|
.run_script(AddLocalRevision2 {
|
|
|
|
content: "456".to_string(),
|
2022-11-02 17:15:27 +08:00
|
|
|
})
|
|
|
|
.await;
|
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
test
|
|
|
|
.run_scripts(vec![
|
|
|
|
AssertNextSyncRevisionId { rev_id: Some(2) },
|
|
|
|
AssertNextSyncRevisionContent {
|
|
|
|
expected: "123456".to_string(),
|
|
|
|
},
|
|
|
|
AckRevision { rev_id: 2 },
|
|
|
|
AssertNextSyncRevisionId { rev_id: None },
|
2022-11-02 17:15:27 +08:00
|
|
|
])
|
|
|
|
.await;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
2022-11-07 17:30:24 +08:00
|
|
|
async fn revision_compress_4_revisions_with_threshold_2_test() {
|
2023-02-13 09:29:49 +08:00
|
|
|
let test = RevisionTest::new_with_configuration(2).await;
|
|
|
|
test
|
|
|
|
.run_script(AddLocalRevision {
|
|
|
|
content: "1".to_string(),
|
2022-11-02 17:15:27 +08:00
|
|
|
})
|
|
|
|
.await;
|
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
test
|
|
|
|
.run_script(AddLocalRevision {
|
|
|
|
content: "2".to_string(),
|
2022-11-02 17:15:27 +08:00
|
|
|
})
|
|
|
|
.await;
|
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
test
|
|
|
|
.run_script(AddLocalRevision {
|
|
|
|
content: "3".to_string(),
|
2022-11-02 17:15:27 +08:00
|
|
|
})
|
|
|
|
.await;
|
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
test
|
|
|
|
.run_script(AddLocalRevision {
|
|
|
|
content: "4".to_string(),
|
2022-11-06 09:59:53 +08:00
|
|
|
})
|
|
|
|
.await;
|
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
test
|
|
|
|
.run_scripts(vec![
|
|
|
|
AssertNumberOfSyncRevisions { num: 2 },
|
|
|
|
AssertNextSyncRevisionId { rev_id: Some(2) },
|
|
|
|
AssertNextSyncRevisionContent {
|
|
|
|
expected: "12".to_string(),
|
|
|
|
},
|
|
|
|
AckRevision { rev_id: 2 },
|
|
|
|
AssertNextSyncRevisionId { rev_id: Some(4) },
|
|
|
|
AssertNextSyncRevisionContent {
|
|
|
|
expected: "34".to_string(),
|
|
|
|
},
|
2022-11-02 17:15:27 +08:00
|
|
|
])
|
|
|
|
.await;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
2022-11-07 17:30:24 +08:00
|
|
|
async fn revision_compress_8_revisions_with_threshold_4_test() {
|
2023-02-13 09:29:49 +08:00
|
|
|
let merge_len = 4;
|
|
|
|
let test = RevisionTest::new_with_configuration(merge_len).await;
|
|
|
|
test
|
|
|
|
.run_script(AddLocalRevision {
|
|
|
|
content: "1".to_string(),
|
2022-11-06 09:59:53 +08:00
|
|
|
})
|
|
|
|
.await;
|
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
test
|
|
|
|
.run_script(AddLocalRevision {
|
|
|
|
content: "2".to_string(),
|
2022-11-06 09:59:53 +08:00
|
|
|
})
|
|
|
|
.await;
|
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
test
|
|
|
|
.run_script(AddLocalRevision {
|
|
|
|
content: "3".to_string(),
|
2022-11-06 09:59:53 +08:00
|
|
|
})
|
|
|
|
.await;
|
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
test
|
|
|
|
.run_script(AddLocalRevision {
|
|
|
|
content: "4".to_string(),
|
2022-11-06 09:59:53 +08:00
|
|
|
})
|
|
|
|
.await;
|
2022-11-02 17:15:27 +08:00
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
test
|
|
|
|
.run_script(AddLocalRevision {
|
|
|
|
content: "a".to_string(),
|
2022-11-06 09:59:53 +08:00
|
|
|
})
|
|
|
|
.await;
|
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
test
|
|
|
|
.run_script(AddLocalRevision {
|
|
|
|
content: "b".to_string(),
|
2022-11-06 09:59:53 +08:00
|
|
|
})
|
|
|
|
.await;
|
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
test
|
|
|
|
.run_script(AddLocalRevision {
|
|
|
|
content: "c".to_string(),
|
2022-11-06 09:59:53 +08:00
|
|
|
})
|
|
|
|
.await;
|
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
test
|
|
|
|
.run_script(AddLocalRevision {
|
|
|
|
content: "d".to_string(),
|
2022-11-06 09:59:53 +08:00
|
|
|
})
|
|
|
|
.await;
|
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
test
|
|
|
|
.run_scripts(vec![
|
|
|
|
AssertNumberOfSyncRevisions { num: 2 },
|
|
|
|
AssertNextSyncRevisionId {
|
|
|
|
rev_id: Some(merge_len),
|
|
|
|
},
|
|
|
|
AssertNextSyncRevisionContent {
|
|
|
|
expected: "1234".to_string(),
|
|
|
|
},
|
|
|
|
AckRevision { rev_id: merge_len },
|
|
|
|
AssertNextSyncRevisionId {
|
|
|
|
rev_id: Some(merge_len * 2),
|
|
|
|
},
|
|
|
|
AssertNextSyncRevisionContent {
|
|
|
|
expected: "abcd".to_string(),
|
|
|
|
},
|
|
|
|
AckRevision {
|
|
|
|
rev_id: merge_len * 2,
|
|
|
|
},
|
|
|
|
AssertNextSyncRevisionId { rev_id: None },
|
2022-11-06 09:59:53 +08:00
|
|
|
])
|
|
|
|
.await;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn revision_merge_per_5_revision_test() {
|
2023-02-13 09:29:49 +08:00
|
|
|
let merge_len = 5;
|
|
|
|
let test = RevisionTest::new_with_configuration(merge_len).await;
|
|
|
|
for i in 0..20 {
|
|
|
|
let content = format!("{}", i);
|
|
|
|
test.run_script(AddLocalRevision { content }).await;
|
|
|
|
}
|
2022-11-02 17:15:27 +08:00
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
test
|
|
|
|
.run_scripts(vec![
|
|
|
|
AssertNumberOfSyncRevisions { num: 4 },
|
|
|
|
AssertNextSyncRevisionContent {
|
|
|
|
expected: "01234".to_string(),
|
|
|
|
},
|
|
|
|
AckRevision { rev_id: merge_len },
|
|
|
|
AssertNextSyncRevisionContent {
|
|
|
|
expected: "56789".to_string(),
|
|
|
|
},
|
|
|
|
AckRevision {
|
|
|
|
rev_id: merge_len * 2,
|
|
|
|
},
|
|
|
|
AssertNextSyncRevisionContent {
|
|
|
|
expected: "1011121314".to_string(),
|
|
|
|
},
|
|
|
|
AckRevision {
|
|
|
|
rev_id: merge_len * 3,
|
|
|
|
},
|
|
|
|
AssertNextSyncRevisionContent {
|
|
|
|
expected: "1516171819".to_string(),
|
|
|
|
},
|
|
|
|
AckRevision {
|
|
|
|
rev_id: merge_len * 4,
|
|
|
|
},
|
|
|
|
AssertNextSyncRevisionId { rev_id: None },
|
2022-11-07 10:09:05 +08:00
|
|
|
])
|
|
|
|
.await;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn revision_merge_per_100_revision_test() {
|
2023-02-13 09:29:49 +08:00
|
|
|
let test = RevisionTest::new_with_configuration(100).await;
|
|
|
|
for i in 0..1000 {
|
|
|
|
let content = format!("{}", i);
|
|
|
|
test.run_script(AddLocalRevision { content }).await;
|
|
|
|
}
|
2022-11-07 10:09:05 +08:00
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
test
|
|
|
|
.run_scripts(vec![AssertNumberOfSyncRevisions { num: 10 }])
|
|
|
|
.await;
|
2022-11-02 17:15:27 +08:00
|
|
|
}
|
2022-11-07 17:30:24 +08:00
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn revision_merge_per_100_revision_test2() {
|
2023-02-13 09:29:49 +08:00
|
|
|
let test = RevisionTest::new_with_configuration(100).await;
|
|
|
|
for i in 0..50 {
|
|
|
|
test
|
|
|
|
.run_script(AddLocalRevision {
|
|
|
|
content: format!("{}", i),
|
|
|
|
})
|
|
|
|
.await;
|
|
|
|
}
|
2022-11-07 17:30:24 +08:00
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
test
|
|
|
|
.run_scripts(vec![AssertNumberOfSyncRevisions { num: 50 }])
|
|
|
|
.await;
|
2022-11-07 17:30:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn revision_merge_per_1000_revision_test() {
|
2023-02-13 09:29:49 +08:00
|
|
|
let test = RevisionTest::new_with_configuration(1000).await;
|
|
|
|
for i in 0..100000 {
|
|
|
|
test
|
|
|
|
.run_script(AddLocalRevision {
|
|
|
|
content: format!("{}", i),
|
|
|
|
})
|
|
|
|
.await;
|
|
|
|
}
|
2022-11-07 17:30:24 +08:00
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
test
|
|
|
|
.run_scripts(vec![AssertNumberOfSyncRevisions { num: 100 }])
|
|
|
|
.await;
|
2022-11-07 17:30:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn revision_compress_revision_test() {
|
2023-02-13 09:29:49 +08:00
|
|
|
let test = RevisionTest::new_with_configuration(2).await;
|
|
|
|
test
|
|
|
|
.run_scripts(vec![
|
|
|
|
AddLocalRevision2 {
|
|
|
|
content: "1".to_string(),
|
|
|
|
},
|
|
|
|
AddLocalRevision2 {
|
|
|
|
content: "2".to_string(),
|
|
|
|
},
|
|
|
|
AddLocalRevision2 {
|
|
|
|
content: "3".to_string(),
|
|
|
|
},
|
|
|
|
AddLocalRevision2 {
|
|
|
|
content: "4".to_string(),
|
|
|
|
},
|
|
|
|
AssertNumberOfSyncRevisions { num: 2 },
|
2022-11-07 17:30:24 +08:00
|
|
|
])
|
|
|
|
.await;
|
|
|
|
}
|
2022-12-09 09:19:47 +08:00
|
|
|
|
2022-11-07 17:30:24 +08:00
|
|
|
#[tokio::test]
|
|
|
|
async fn revision_compress_revision_while_recv_ack_test() {
|
2023-02-13 09:29:49 +08:00
|
|
|
let test = RevisionTest::new_with_configuration(2).await;
|
|
|
|
test
|
|
|
|
.run_scripts(vec![
|
|
|
|
AddLocalRevision2 {
|
|
|
|
content: "1".to_string(),
|
|
|
|
},
|
|
|
|
AckRevision { rev_id: 1 },
|
|
|
|
AddLocalRevision2 {
|
|
|
|
content: "2".to_string(),
|
|
|
|
},
|
|
|
|
AckRevision { rev_id: 2 },
|
|
|
|
AddLocalRevision2 {
|
|
|
|
content: "3".to_string(),
|
|
|
|
},
|
|
|
|
AckRevision { rev_id: 3 },
|
|
|
|
AddLocalRevision2 {
|
|
|
|
content: "4".to_string(),
|
|
|
|
},
|
|
|
|
AssertNumberOfSyncRevisions { num: 4 },
|
2022-11-07 17:30:24 +08:00
|
|
|
])
|
|
|
|
.await;
|
|
|
|
}
|