| 
									
										
										
										
											2022-11-02 17:15:27 +08:00
										 |  |  | use crate::revision_test::script::{RevisionScript::*, RevisionTest};
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #[tokio::test]
 | 
					
						
							|  |  |  | async fn revision_sync_test() {
 | 
					
						
							|  |  |  |     let test = RevisionTest::new().await;
 | 
					
						
							| 
									
										
										
										
											2022-12-09 09:19:47 +08:00
										 |  |  |     let rev_id = 1;
 | 
					
						
							| 
									
										
										
										
											2022-11-02 17:15:27 +08:00
										 |  |  |     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]
 | 
					
						
							| 
									
										
										
										
											2022-11-07 17:30:24 +08:00
										 |  |  | async fn revision_compress_2_revisions_with_2_threshold_test() {
 | 
					
						
							| 
									
										
										
										
											2022-11-06 09:59:53 +08:00
										 |  |  |     let test = RevisionTest::new_with_configuration(2).await;
 | 
					
						
							| 
									
										
										
										
											2022-11-07 17:30:24 +08:00
										 |  |  |     test.run_script(AddLocalRevision2 {
 | 
					
						
							| 
									
										
										
										
											2022-11-02 17:15:27 +08:00
										 |  |  |         content: "123".to_string(),
 | 
					
						
							|  |  |  |     })
 | 
					
						
							|  |  |  |     .await;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-07 17:30:24 +08:00
										 |  |  |     test.run_script(AddLocalRevision2 {
 | 
					
						
							| 
									
										
										
										
											2022-11-02 17:15:27 +08:00
										 |  |  |         content: "456".to_string(),
 | 
					
						
							|  |  |  |     })
 | 
					
						
							|  |  |  |     .await;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test.run_scripts(vec![
 | 
					
						
							| 
									
										
										
										
											2022-11-07 17:30:24 +08:00
										 |  |  |         AssertNextSyncRevisionId { rev_id: Some(1) },
 | 
					
						
							| 
									
										
										
										
											2022-12-09 09:19:47 +08:00
										 |  |  |         AssertNextSyncRevisionContent {
 | 
					
						
							|  |  |  |             expected: "123456".to_string(),
 | 
					
						
							|  |  |  |         },
 | 
					
						
							| 
									
										
										
										
											2022-11-07 17:30:24 +08:00
										 |  |  |         AckRevision { rev_id: 1 },
 | 
					
						
							| 
									
										
										
										
											2022-11-02 17:15:27 +08:00
										 |  |  |         AssertNextSyncRevisionId { rev_id: None },
 | 
					
						
							|  |  |  |     ])
 | 
					
						
							|  |  |  |     .await;
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #[tokio::test]
 | 
					
						
							| 
									
										
										
										
											2022-11-07 17:30:24 +08:00
										 |  |  | async fn revision_compress_4_revisions_with_threshold_2_test() {
 | 
					
						
							| 
									
										
										
										
											2022-11-06 09:59:53 +08:00
										 |  |  |     let test = RevisionTest::new_with_configuration(2).await;
 | 
					
						
							| 
									
										
										
										
											2022-12-09 09:19:47 +08:00
										 |  |  |     let rev_id_1 = 1;
 | 
					
						
							| 
									
										
										
										
											2022-11-02 17:15:27 +08:00
										 |  |  |     test.run_script(AddLocalRevision {
 | 
					
						
							| 
									
										
										
										
											2022-11-06 09:59:53 +08:00
										 |  |  |         content: "1".to_string(),
 | 
					
						
							| 
									
										
										
										
											2022-11-02 17:15:27 +08:00
										 |  |  |     })
 | 
					
						
							|  |  |  |     .await;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-09 09:19:47 +08:00
										 |  |  |     let rev_id_2 = 2;
 | 
					
						
							| 
									
										
										
										
											2022-11-02 17:15:27 +08:00
										 |  |  |     test.run_script(AddLocalRevision {
 | 
					
						
							| 
									
										
										
										
											2022-11-06 09:59:53 +08:00
										 |  |  |         content: "2".to_string(),
 | 
					
						
							| 
									
										
										
										
											2022-11-02 17:15:27 +08:00
										 |  |  |     })
 | 
					
						
							|  |  |  |     .await;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test.run_script(AddLocalRevision {
 | 
					
						
							| 
									
										
										
										
											2022-11-06 09:59:53 +08:00
										 |  |  |         content: "3".to_string(),
 | 
					
						
							| 
									
										
										
										
											2022-11-02 17:15:27 +08:00
										 |  |  |     })
 | 
					
						
							|  |  |  |     .await;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-06 09:59:53 +08:00
										 |  |  |     test.run_script(AddLocalRevision {
 | 
					
						
							|  |  |  |         content: "4".to_string(),
 | 
					
						
							|  |  |  |     })
 | 
					
						
							|  |  |  |     .await;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // rev_id_2,rev_id_3,rev_id4 will be merged into rev_id_1
 | 
					
						
							| 
									
										
										
										
											2022-11-02 17:15:27 +08:00
										 |  |  |     test.run_scripts(vec![
 | 
					
						
							| 
									
										
										
										
											2022-11-07 17:30:24 +08:00
										 |  |  |         AssertNumberOfSyncRevisions { num: 2 },
 | 
					
						
							| 
									
										
										
										
											2022-11-02 17:15:27 +08:00
										 |  |  |         AssertNextSyncRevisionId { rev_id: Some(rev_id_1) },
 | 
					
						
							|  |  |  |         AssertNextSyncRevisionContent {
 | 
					
						
							| 
									
										
										
										
											2022-11-07 17:30:24 +08:00
										 |  |  |             expected: "12".to_string(),
 | 
					
						
							| 
									
										
										
										
											2022-11-02 17:15:27 +08:00
										 |  |  |         },
 | 
					
						
							| 
									
										
										
										
											2022-11-06 09:59:53 +08:00
										 |  |  |         AckRevision { rev_id: rev_id_1 },
 | 
					
						
							| 
									
										
										
										
											2022-11-07 17:30:24 +08:00
										 |  |  |         AssertNextSyncRevisionId { rev_id: Some(rev_id_2) },
 | 
					
						
							|  |  |  |         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() {
 | 
					
						
							|  |  |  |     let test = RevisionTest::new_with_configuration(4).await;
 | 
					
						
							| 
									
										
										
										
											2022-12-09 09:19:47 +08:00
										 |  |  |     let rev_id_1 = 1;
 | 
					
						
							| 
									
										
										
										
											2022-11-06 09:59:53 +08:00
										 |  |  |     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;
 | 
					
						
							| 
									
										
										
										
											2022-11-02 17:15:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-09 09:19:47 +08:00
										 |  |  |     let rev_id_a = 2;
 | 
					
						
							| 
									
										
										
										
											2022-11-06 09:59:53 +08:00
										 |  |  |     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(rev_id_1) },
 | 
					
						
							|  |  |  |         AssertNextSyncRevisionContent {
 | 
					
						
							|  |  |  |             expected: "1234".to_string(),
 | 
					
						
							|  |  |  |         },
 | 
					
						
							|  |  |  |         AckRevision { rev_id: rev_id_1 },
 | 
					
						
							|  |  |  |         AssertNextSyncRevisionId { rev_id: Some(rev_id_a) },
 | 
					
						
							|  |  |  |         AssertNextSyncRevisionContent {
 | 
					
						
							|  |  |  |             expected: "abcd".to_string(),
 | 
					
						
							|  |  |  |         },
 | 
					
						
							|  |  |  |         AckRevision { rev_id: rev_id_a },
 | 
					
						
							|  |  |  |         AssertNextSyncRevisionId { rev_id: None },
 | 
					
						
							|  |  |  |     ])
 | 
					
						
							|  |  |  |     .await;
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #[tokio::test]
 | 
					
						
							|  |  |  | async fn revision_merge_per_5_revision_test() {
 | 
					
						
							| 
									
										
										
										
											2022-11-07 10:09:05 +08:00
										 |  |  |     let test = RevisionTest::new_with_configuration(5).await;
 | 
					
						
							| 
									
										
										
										
											2022-11-06 09:59:53 +08:00
										 |  |  |     for i in 0..20 {
 | 
					
						
							| 
									
										
										
										
											2022-11-02 17:15:27 +08:00
										 |  |  |         let content = format!("{}", i);
 | 
					
						
							| 
									
										
										
										
											2022-12-09 09:19:47 +08:00
										 |  |  |         test.run_script(AddLocalRevision { content }).await;
 | 
					
						
							| 
									
										
										
										
											2022-11-02 17:15:27 +08:00
										 |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-07 10:09:05 +08:00
										 |  |  |     test.run_scripts(vec![
 | 
					
						
							|  |  |  |         AssertNumberOfSyncRevisions { num: 4 },
 | 
					
						
							|  |  |  |         AssertNextSyncRevisionContent {
 | 
					
						
							|  |  |  |             expected: "01234".to_string(),
 | 
					
						
							|  |  |  |         },
 | 
					
						
							|  |  |  |         AckRevision { rev_id: 1 },
 | 
					
						
							|  |  |  |         AssertNextSyncRevisionContent {
 | 
					
						
							|  |  |  |             expected: "56789".to_string(),
 | 
					
						
							|  |  |  |         },
 | 
					
						
							|  |  |  |         AckRevision { rev_id: 2 },
 | 
					
						
							|  |  |  |         AssertNextSyncRevisionContent {
 | 
					
						
							|  |  |  |             expected: "1011121314".to_string(),
 | 
					
						
							|  |  |  |         },
 | 
					
						
							|  |  |  |         AckRevision { rev_id: 3 },
 | 
					
						
							|  |  |  |         AssertNextSyncRevisionContent {
 | 
					
						
							|  |  |  |             expected: "1516171819".to_string(),
 | 
					
						
							|  |  |  |         },
 | 
					
						
							|  |  |  |         AckRevision { rev_id: 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);
 | 
					
						
							| 
									
										
										
										
											2022-12-09 09:19:47 +08:00
										 |  |  |         test.run_script(AddLocalRevision { content }).await;
 | 
					
						
							| 
									
										
										
										
											2022-11-07 10:09:05 +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() {
 | 
					
						
							|  |  |  |     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;
 | 
					
						
							|  |  |  | }
 | 
					
						
							| 
									
										
										
										
											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() {
 | 
					
						
							|  |  |  |     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;
 | 
					
						
							|  |  |  | }
 |