Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Commit

Permalink
Message ordering test
Browse files Browse the repository at this point in the history
  • Loading branch information
Veritius committed Jul 5, 2024
1 parent 0dfbf5f commit 5586e2d
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions stardust/src/messages/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,44 @@ impl<'a> ExactSizeIterator for MessageIter<'a> {
fn len(&self) -> usize {
self.indexes.len()
}
}

#[test]
fn message_queue_ordering_test() {
let mut queue = MessageQueue::new();

fn map_messages(set: &'static [&'static [u8]]) -> impl Iterator<Item = Message> {
set.iter().map(|v| Message::from_bytes(Bytes::from_static(v)))
}

const MESSAGE_SET_A: &[&[u8]] = &[
b"Hello, world!",
b"It's a very nice day, isn't it?",
b"Yeah, I agree!",
];

const MESSAGE_SET_B: &[&[u8]] = &[
b"Hello, world!",
b"It's a miserable day, isn't it?",
b"No, I think it's fine!",
];

const MESSAGE_SET_C: &[&[u8]] = &[
b"Hello, world!",
b"It's an alright day, isn't it?",
b"That's a good way of putting it.",
];

// Add all the messages to the channel
queue.push_channel(ChannelId::from(0), map_messages(MESSAGE_SET_A));
queue.push_channel(ChannelId::from(0), map_messages(MESSAGE_SET_B));
queue.push_channel(ChannelId::from(1), map_messages(MESSAGE_SET_C));

queue.iter_channel(ChannelId::from(0))
.zip(MESSAGE_SET_A.iter().chain(MESSAGE_SET_B))
.for_each(|(a, b)| assert_eq!(a.as_slice(), *b));

queue.iter_channel(ChannelId::from(1))
.zip(MESSAGE_SET_C)
.for_each(|(a, b)| assert_eq!(a.as_slice(), *b));
}

0 comments on commit 5586e2d

Please sign in to comment.