123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- use crate::revision_test::script::{RevisionScript::*, RevisionTest};
- #[tokio::test]
- async fn revision_sync_test() {
- let test = RevisionTest::new().await;
- let rev_id = 1;
- test
- .run_script(AddLocalRevision {
- content: "123".to_string(),
- })
- .await;
- 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;
- }
- #[tokio::test]
- async fn revision_compress_2_revisions_with_2_threshold_test() {
- let test = RevisionTest::new_with_configuration(2).await;
- test
- .run_script(AddLocalRevision2 {
- content: "123".to_string(),
- })
- .await;
- test
- .run_script(AddLocalRevision2 {
- content: "456".to_string(),
- })
- .await;
- test
- .run_scripts(vec![
- AssertNextSyncRevisionId { rev_id: Some(2) },
- AssertNextSyncRevisionContent {
- expected: "123456".to_string(),
- },
- AckRevision { rev_id: 2 },
- AssertNextSyncRevisionId { rev_id: None },
- ])
- .await;
- }
- #[tokio::test]
- async fn revision_compress_4_revisions_with_threshold_2_test() {
- let test = RevisionTest::new_with_configuration(2).await;
- test
- .run_script(AddLocalRevision {
- content: "1".to_string(),
- })
- .await;
- test
- .run_script(AddLocalRevision {
- content: "2".to_string(),
- })
- .await;
- test
- .run_script(AddLocalRevision {
- content: "3".to_string(),
- })
- .await;
- test
- .run_script(AddLocalRevision {
- content: "4".to_string(),
- })
- .await;
- 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(),
- },
- ])
- .await;
- }
- #[tokio::test]
- async fn revision_compress_8_revisions_with_threshold_4_test() {
- let merge_len = 4;
- let test = RevisionTest::new_with_configuration(merge_len).await;
- test
- .run_script(AddLocalRevision {
- content: "1".to_string(),
- })
- .await;
- test
- .run_script(AddLocalRevision {
- content: "2".to_string(),
- })
- .await;
- test
- .run_script(AddLocalRevision {
- content: "3".to_string(),
- })
- .await;
- test
- .run_script(AddLocalRevision {
- content: "4".to_string(),
- })
- .await;
- test
- .run_script(AddLocalRevision {
- content: "a".to_string(),
- })
- .await;
- test
- .run_script(AddLocalRevision {
- content: "b".to_string(),
- })
- .await;
- test
- .run_script(AddLocalRevision {
- content: "c".to_string(),
- })
- .await;
- test
- .run_script(AddLocalRevision {
- content: "d".to_string(),
- })
- .await;
- 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 },
- ])
- .await;
- }
- #[tokio::test]
- async fn revision_merge_per_5_revision_test() {
- 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;
- }
- 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 },
- ])
- .await;
- }
- #[tokio::test]
- async fn revision_merge_per_100_revision_test() {
- let test = RevisionTest::new_with_configuration(100).await;
- for i in 0..1000 {
- let content = format!("{}", i);
- test.run_script(AddLocalRevision { content }).await;
- }
- test
- .run_scripts(vec![AssertNumberOfSyncRevisions { num: 10 }])
- .await;
- }
- #[tokio::test]
- async fn revision_merge_per_100_revision_test2() {
- let test = RevisionTest::new_with_configuration(100).await;
- for i in 0..50 {
- test
- .run_script(AddLocalRevision {
- content: format!("{}", i),
- })
- .await;
- }
- test
- .run_scripts(vec![AssertNumberOfSyncRevisions { num: 50 }])
- .await;
- }
- // #[tokio::test]
- // async fn revision_merge_per_1000_revision_test() {
- // let test = RevisionTest::new_with_configuration(1000).await;
- // for i in 0..100000 {
- // test
- // .run_script(AddLocalRevision {
- // content: format!("{}", i),
- // })
- // .await;
- // }
- //
- // test
- // .run_scripts(vec![AssertNumberOfSyncRevisions { num: 100 }])
- // .await;
- // }
- #[tokio::test]
- async fn revision_compress_revision_test() {
- 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 },
- ])
- .await;
- }
- #[tokio::test]
- async fn revision_compress_revision_while_recv_ack_test() {
- 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 },
- ])
- .await;
- }
|