Skip to content

Commit

Permalink
add test to show balanced distribution in specific case
Browse files Browse the repository at this point in the history
  • Loading branch information
4meta5 committed Jul 19, 2024
1 parent 2cb61f4 commit 2157fb2
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions pallets/tasks/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1852,6 +1852,45 @@ fn test_assingment_with_diff_shard_size() {
});
}

#[test]
fn balanced_distribution_when_more_unassigned_tasks_than_task_limit() {
new_test_ext().execute_with(|| {
const NUM_SHARDS: u64 = 4;
for i in 0..NUM_SHARDS {
Shards::create_shard(
ETHEREUM,
[[0u8; 32].into(), [1u8; 32].into(), [2u8; 32].into()].to_vec(),
1,
);
ShardState::<Test>::insert(i, ShardStatus::Online);
}
for _ in 0..200 {
assert_ok!(Tasks::create_task(
RawOrigin::Signed([0; 32].into()).into(),
mock_task(ETHEREUM, 3)
));
}
assert_eq!(
UnassignedTasks::<Test>::iter().map(|(_, _, t)| t).collect::<Vec<_>>().len(),
200
);
assert_ok!(Tasks::set_shard_task_limit(RawOrigin::Root.into(), ETHEREUM, 50));
for i in 0..NUM_SHARDS {
Tasks::shard_online(i, ETHEREUM);
}
assert!(UnassignedTasks::<Test>::iter()
.map(|(_, _, t)| t)
.collect::<Vec<_>>()
.is_empty());
for i in 0..NUM_SHARDS {
assert_eq!(
ShardTasks::<Test>::iter_prefix(i).map(|(t, _)| t).collect::<Vec<_>>().len(),
50
);
}
});
}

#[test]
fn first_shard_online_assigned_up_to_task_limit() {
new_test_ext().execute_with(|| {
Expand Down

0 comments on commit 2157fb2

Please sign in to comment.