diff --git a/integration-tests/src/test_loop/tests/resharding_v3.rs b/integration-tests/src/test_loop/tests/resharding_v3.rs index c6b39c8eff1..658f6bcc78b 100644 --- a/integration-tests/src/test_loop/tests/resharding_v3.rs +++ b/integration-tests/src/test_loop/tests/resharding_v3.rs @@ -50,7 +50,7 @@ const INCREASED_EPOCH_LENGTH: u64 = 8; const GC_NUM_EPOCHS_TO_KEEP: u64 = 3; /// Maximum number of epochs under which the test should finish. -const TESTLOOP_NUM_EPOCHS_TO_WAIT: u64 = 8; +const TESTLOOP_NUM_EPOCHS_TO_WAIT: u64 = 10; /// Default shard layout version used in resharding tests. const DEFAULT_SHARD_LAYOUT_VERSION: u64 = 2; @@ -135,7 +135,7 @@ struct TestReshardingParameters { impl TestReshardingParametersBuilder { fn build(self) -> TestReshardingParameters { // Give enough time for GC to kick in after resharding. - assert!(GC_NUM_EPOCHS_TO_KEEP + 2 < TESTLOOP_NUM_EPOCHS_TO_WAIT); + assert!(GC_NUM_EPOCHS_TO_KEEP + 3 < TESTLOOP_NUM_EPOCHS_TO_WAIT); let epoch_length = self.epoch_length.unwrap_or(DEFAULT_EPOCH_LENGTH); let tracked_shard_schedule = self.tracked_shard_schedule.unwrap_or(None); @@ -513,7 +513,7 @@ fn test_resharding_v3_base(params: TestReshardingParameters) { resharding_block_hash.set(Some(tip.prev_block_hash)); epoch_height_after_resharding.set(Some(epoch_height)); // Assert that we will have a chance for gc to kick in before the test is over. - assert!(epoch_height + GC_NUM_EPOCHS_TO_KEEP < TESTLOOP_NUM_EPOCHS_TO_WAIT); + assert!(epoch_height + GC_NUM_EPOCHS_TO_KEEP + 1 < TESTLOOP_NUM_EPOCHS_TO_WAIT); println!("State after resharding:"); print_and_assert_shard_accounts(&clients, &tip); } @@ -528,7 +528,7 @@ fn test_resharding_v3_base(params: TestReshardingParameters) { } // Return false if garbage collection window has not passed yet since resharding. - if epoch_height <= epoch_height_after_resharding.get().unwrap() + GC_NUM_EPOCHS_TO_KEEP { + if epoch_height <= TESTLOOP_NUM_EPOCHS_TO_WAIT { return false; } for loop_action in ¶ms.loop_actions { @@ -539,7 +539,7 @@ fn test_resharding_v3_base(params: TestReshardingParameters) { env.test_loop.run_until( success_condition, - // Give enough time to produce ~TESTLOOP_NUM_EPOCHS_TO_WAIT epochs. + // Give enough time to produce TESTLOOP_NUM_EPOCHS_TO_WAIT epochs. Duration::seconds((TESTLOOP_NUM_EPOCHS_TO_WAIT * params.epoch_length) as i64), ); let client = &env.test_loop.data.get(&client_handles[client_index]).client; @@ -621,6 +621,40 @@ fn test_resharding_v3_do_not_track_children_after_resharding() { ); } +#[test] +fn test_resharding_v3_stop_track_child_for_2_epochs() { + // Track parent shard before resharding, and a child shard after resharding. + // Then do not track the child for 2 epochs and start tracking it again. + let account_in_stable_shard: AccountId = "account0".parse().unwrap(); + let split_boundary_account: AccountId = NEW_BOUNDARY_ACCOUNT.parse().unwrap(); + let base_shard_layout = get_base_shard_layout(DEFAULT_SHARD_LAYOUT_VERSION); + let new_shard_layout = + ShardLayout::derive_shard_layout(&base_shard_layout, split_boundary_account.clone()); + let parent_shard_id = base_shard_layout.account_id_to_shard_id(&split_boundary_account); + let child_shard_id = new_shard_layout.account_id_to_shard_id(&split_boundary_account); + let unrelated_shard_id = new_shard_layout.account_id_to_shard_id(&account_in_stable_shard); + + let tracked_shard_sequence = vec![ + parent_shard_id, + parent_shard_id, + child_shard_id, + unrelated_shard_id, + unrelated_shard_id, + child_shard_id, + ]; + let num_clients = 8; + let tracked_shard_schedule = TrackedShardSchedule { + client_index: (num_clients - 1) as usize, + schedule: shard_sequence_to_schedule(tracked_shard_sequence), + }; + test_resharding_v3_base( + TestReshardingParametersBuilder::default() + .num_clients(num_clients) + .tracked_shard_schedule(Some(tracked_shard_schedule)) + .build(), + ); +} + #[test] fn test_resharding_v3_track_all_shards() { test_resharding_v3_base(