Skip to content

Commit

Permalink
add test, extend test duration
Browse files Browse the repository at this point in the history
  • Loading branch information
staffik committed Jan 10, 2025
1 parent c617d07 commit e9a8b26
Showing 1 changed file with 42 additions and 5 deletions.
47 changes: 42 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 @@ -486,11 +486,12 @@ fn test_resharding_v3_base(params: TestReshardingParameters) {
let shard_layout = client.epoch_manager.get_shard_layout(&tip.epoch_id).unwrap();

println!(
"new block #{} shards: {:?} chunk mask {:?} block hash {}",
"new block #{} shards: {:?} chunk mask {:?} block hash {} epoch id {:?}",
tip.height,
shard_layout.shard_ids().collect_vec(),
block_header.chunk_mask().to_vec(),
tip.last_block_hash,
tip.epoch_id.0,
);

// Check that all chunks are included.
Expand Down Expand Up @@ -528,7 +529,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 +540,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 +622,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 Expand Up @@ -712,6 +747,8 @@ fn test_resharding_v3_double_sign_resharding_block() {
}

#[test]
// TODO(resharding): fix nearcore and un-ignore this test
#[ignore]
fn test_resharding_v3_shard_shuffling() {
let params = TestReshardingParametersBuilder::default()
.shuffle_shard_assignment_for_chunk_producers(true)
Expand Down

0 comments on commit e9a8b26

Please sign in to comment.