From e99cfebbc7a485fe55efe476c083d9decc888ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=82=8E=E6=B3=BC?= Date: Wed, 6 Nov 2024 18:13:38 +0800 Subject: [PATCH] Test: split storage test get_initial_state_membership_from_log_and_sm() into 3 sub tests --- openraft/src/testing/log/suite.rs | 43 ++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/openraft/src/testing/log/suite.rs b/openraft/src/testing/log/suite.rs index 00c414653..a5771273c 100644 --- a/openraft/src/testing/log/suite.rs +++ b/openraft/src/testing/log/suite.rs @@ -134,7 +134,9 @@ where run_test(builder, Self::get_membership_from_log_gt_sm_last_applied_1).await?; run_test(builder, Self::get_membership_from_log_gt_sm_last_applied_2).await?; run_test(builder, Self::get_initial_state_without_init).await?; - run_test(builder, Self::get_initial_state_membership_from_log_and_sm).await?; + run_test(builder, Self::get_initial_state_membership_from_empty_log_and_sm).await?; + run_test(builder, Self::get_initial_state_membership_from_sm_inlog_is_smaller).await?; + run_test(builder, Self::get_initial_state_membership_from_log_insm_is_smaller).await?; run_test(builder, Self::get_initial_state_with_state).await?; run_test(builder, Self::get_initial_state_last_log_gt_sm).await?; run_test(builder, Self::get_initial_state_last_log_lt_sm).await?; @@ -480,7 +482,7 @@ where Ok(()) } - pub async fn get_initial_state_membership_from_log_and_sm( + pub async fn get_initial_state_membership_from_empty_log_and_sm( mut store: LS, mut sm: SM, ) -> Result<(), StorageError> { @@ -488,8 +490,6 @@ where Self::default_vote(&mut store).await?; - // copy the test from get_membership_config - tracing::info!("--- no log, read membership from state machine"); { apply(&mut sm, [ @@ -506,8 +506,25 @@ where ); } + Ok(()) + } + + pub async fn get_initial_state_membership_from_sm_inlog_is_smaller( + mut store: LS, + mut sm: SM, + ) -> Result<(), StorageError> { + // It should never return membership from logs that are included in state machine present. + + Self::default_vote(&mut store).await?; + tracing::info!("--- membership presents in log, but smaller than last_applied, read from state machine"); { + apply(&mut sm, [ + blank_ent_0::(1, 1), + membership_ent_0::(1, 2, btreeset! {3,4,5}), + ]) + .await?; + append(&mut store, [membership_ent_0::(1, 1, btreeset! {1,2,3})]).await?; let initial = StorageHelper::new(&mut store, &mut sm).get_initial_state().await?; @@ -518,8 +535,26 @@ where ); } + Ok(()) + } + + pub async fn get_initial_state_membership_from_log_insm_is_smaller( + mut store: LS, + mut sm: SM, + ) -> Result<(), StorageError> { + // It should never return membership from logs that are included in state machine present. + + Self::default_vote(&mut store).await?; + tracing::info!("--- membership presents in log and > sm.last_applied, read from log"); { + apply(&mut sm, [ + blank_ent_0::(1, 1), + membership_ent_0::(1, 2, btreeset! {3,4,5}), + ]) + .await?; + + store.purge(log_id_0(1, 2)).await?; append(&mut store, [membership_ent_0::(1, 3, btreeset! {1,2,3})]).await?; let initial = StorageHelper::new(&mut store, &mut sm).get_initial_state().await?;