use messaging_thread_pool::{ThreadPool, samples::*};
#[test]
pub fn example_chat_room() {
let thread_pool = ThreadPool::<ChatRoom>::new(2);
let room_general = 1;
let room_tech = 2;
thread_pool
.send_and_receive(vec![ChatRoomInit(room_general), ChatRoomInit(room_tech)].into_iter())
.expect("creation requests")
.for_each(|_| {});
thread_pool
.send_and_receive(
vec![
PostRequest(
room_general,
"Alice".to_string(),
"Hello everyone!".to_string(),
),
PostRequest(room_general, "Bob".to_string(), "Hi Alice!".to_string()),
]
.into_iter(),
)
.expect("messages to send")
.for_each(|response| {
assert!(response.result < 100);
});
thread_pool
.send_and_receive(
vec![PostRequest(
room_tech,
"Charlie".to_string(),
"Rust is cool".to_string(),
)]
.into_iter(),
)
.expect("messages to send")
.for_each(|_| {});
let history_response = thread_pool
.send_and_receive(vec![GetHistoryRequest(room_general)].into_iter())
.expect("request to send")
.next()
.expect("response");
let history = history_response.result;
assert_eq!(history.len(), 2);
assert_eq!(history[0], "Alice: Hello everyone!");
assert_eq!(history[1], "Bob: Hi Alice!");
let history_response = thread_pool
.send_and_receive(vec![GetHistoryRequest(room_tech)].into_iter())
.expect("request to send")
.next()
.expect("response");
let history = history_response.result;
assert_eq!(history.len(), 1);
assert_eq!(history[0], "Charlie: Rust is cool");
}