Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
  • Loading branch information
ggwpez committed Feb 24, 2023
commit 15a10880408786b15c40a3be5c388422779c07e6
7 changes: 5 additions & 2 deletions frame/message-queue/src/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
#![cfg(test)]

use crate::{
mock::{new_test_ext, IntoWeight, MockedWeightInfo, NumMessagesProcessed, SuspendedQueues},
mock::{
new_test_ext, CountingMessageProcessor, IntoWeight, MockedWeightInfo, NumMessagesProcessed,
SuspendedQueues,
},
mock_helpers::MessageOrigin,
*,
};
Expand Down Expand Up @@ -90,7 +93,7 @@ parameter_types! {
impl Config for Test {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = MockedWeightInfo;
type MessageProcessor = mock::CountingMessageProcessor;
type MessageProcessor = CountingMessageProcessor;
type Size = u32;
type QueueChangeHandler = ();
type HeapSize = HeapSize;
Expand Down
6 changes: 5 additions & 1 deletion frame/message-queue/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,11 @@ pub fn set_weight(name: &str, w: Weight) {

/// Assert that exactly these pages are present. Assumes `Here` origin.
pub fn assert_pages(indices: &[u32]) {
assert_eq!(Pages::<Test>::iter().count(), indices.len(), "Wrong number of pages in the queue");
assert_eq!(
Pages::<Test>::iter_keys().count(),
indices.len(),
"Wrong number of pages in the queue"
);
for i in indices {
assert!(Pages::<Test>::contains_key(MessageOrigin::Here, i));
}
Expand Down
54 changes: 53 additions & 1 deletion frame/message-queue/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ fn service_page_works() {
assert_eq!(status, Bailed);
}
}
assert!(!Pages::<Test>::contains_key(Here, 0), "The page got removed");
assert_pages(&[]);
});
}

Expand Down Expand Up @@ -503,6 +503,58 @@ fn service_page_item_bails() {
});
}

#[test]
fn service_page_suspension_works() {
use super::integration_test::Test; // Run with larger page size.
use MessageOrigin::*;
use PageExecutionStatus::*;

new_test_ext::<Test>().execute_with(|| {
let (page, mut msgs) = full_page::<Test>();
assert!(msgs >= 10, "pre-condition: need at least 10 msgs per page");
let mut book = book_for::<Test>(&page);
Pages::<Test>::insert(Here, 0, page);

// First we process 5 messages from this page.
let mut meter = WeightMeter::from_limit(5.into_weight());
let (_, status) =
crate::Pallet::<Test>::service_page(&Here, &mut book, &mut meter, Weight::MAX);

assert_eq!(NumMessagesProcessed::take(), 5);
assert!(meter.remaining().is_zero());
assert_eq!(status, Bailed); // It bailed since weight is missing.
msgs -= 5;

// Then we pause the queue.
SuspendedQueues::set(vec![Here]);
// Noting happens...
for _ in 0..5 {
let (_, status) = crate::Pallet::<Test>::service_page(
&Here,
&mut book,
&mut WeightMeter::max_limit(),
Weight::MAX,
);
assert_eq!(status, NoProgress);
assert!(NumMessagesProcessed::take().is_zero());
}

// Resume and process all remaining.
SuspendedQueues::take();
let (_, status) = crate::Pallet::<Test>::service_page(
&Here,
&mut book,
&mut WeightMeter::max_limit(),
Weight::MAX,
);
assert_eq!(status, NoMore);
assert_eq!(NumMessagesProcessed::take(), msgs);

assert!(Pages::<Test>::iter_keys().count().is_zero());
MessageQueue::do_try_state().expect("Pallet is in a valid state");
});
}

#[test]
fn bump_service_head_works() {
use MessageOrigin::*;
Expand Down