Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
staffik committed Jan 10, 2025
1 parent c617d07 commit 7f6d7bb
Showing 1 changed file with 39 additions and 5 deletions.
44 changes: 39 additions & 5 deletions integration-tests/src/test_loop/tests/resharding_v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
Expand All @@ -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 &params.loop_actions {
Expand All @@ -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;
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 7f6d7bb

Please sign in to comment.