Skip to content

Commit

Permalink
add test reject_split_shard_if_parent_is_not_ready
Browse files Browse the repository at this point in the history
  • Loading branch information
Trisfald committed Oct 1, 2024
1 parent ac6d642 commit 9269c37
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions chain/chain/src/flat_storage_resharder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,20 +872,13 @@ mod tests {
let scheduler = TestScheduler {};
let controller = FlatStorageResharderController::new();

let result = resharder.split_shard(
ReshardingSplitParams {
parent_shard: ShardUId { version: 3, shard_id: 1 },
left_child_shard: ShardUId { version: 3, shard_id: 2 },
right_child_shard: ShardUId { version: 3, shard_id: 3 },
},
&new_shard_layout,
&scheduler,
controller.clone(),
);
// TODO(Trisfald): replace the above with this simple call
// let result =
// resharder.start_resharding_from_new_shard_layout(&new_shard_layout, &scheduler);
assert!(result.is_ok());
assert!(resharder
.start_resharding_from_new_shard_layout(
&new_shard_layout,
&scheduler,
controller.clone()
)
.is_ok());

// Check flat storages of children contain the correct accounts.
let left_child = ShardUId { version: 3, shard_id: 2 };
Expand Down Expand Up @@ -966,4 +959,25 @@ mod tests {
assert_eq!(flat_store.iter(child_shard).count(), 0);
}
}

/// A shard can't be split if it isn't in ready state.
#[test]
fn reject_split_shard_if_parent_is_not_ready() {
let (_, resharder) = create_fs_resharder(simple_shard_layout());
let new_shard_layout = shard_layout_after_split();
let scheduler = TestScheduler {};
let controller = FlatStorageResharderController::new();

// Make flat storage of parent shard not ready.
let parent_shard = ShardUId { version: 3, shard_id: 1 };
let flat_store = resharder.inner.runtime.store().flat_store();
let mut store_update = flat_store.store_update();
store_update.set_flat_storage_status(parent_shard, FlatStorageStatus::Empty);
store_update.commit().unwrap();

// Trigger resharding and it should fail.
assert!(resharder
.start_resharding_from_new_shard_layout(&new_shard_layout, &scheduler, controller)
.is_err());
}
}

0 comments on commit 9269c37

Please sign in to comment.