#[cfg(feature = "msgpack_serializer")]
mod msgpack {
use lunatic::serializer::MessagePack;
use lunatic::{test, Mailbox, Process, Tag};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
struct ProcBincode(Process<ProcMsgPack>);
#[derive(Serialize, Deserialize)]
struct ProcMsgPack(Process<i32, MessagePack>);
#[test]
fn msg_pack_serializer(mailbox: Mailbox<ProcMsgPack>) {
let parent = mailbox.this();
Process::spawn_link(
ProcBincode(parent),
|parent, _: Mailbox<(), MessagePack>| {
Process::spawn_link(parent, |grandparent, mailbox: Mailbox<i32, MessagePack>| {
grandparent.0.send(ProcMsgPack(mailbox.this()));
let a = mailbox.receive();
let b = mailbox.receive();
assert_eq!(a + b, 5);
grandparent.0.send(ProcMsgPack(mailbox.this()));
});
},
);
let grandchild = mailbox.receive();
grandchild.0.link();
grandchild.0.send(8);
grandchild.0.send(-3);
let _ = mailbox.receive();
}
#[test]
fn message_equality(mailbox: Mailbox<Vec<i32>>) {
let parent = mailbox.this();
let child = Process::spawn_link(
parent,
|parent, child_mailbox: Mailbox<Vec<i32>, MessagePack>| {
let input = child_mailbox.receive();
parent.send(input);
},
);
let input = vec![127; 500];
child.send(input.clone());
let output = mailbox.receive();
assert_eq!(input, output);
}
#[test]
fn tagged_message(mailbox: Mailbox<()>) {
let parent = mailbox.this();
let child = Process::spawn_link(
parent,
|parent, child_mailbox: Mailbox<u64, MessagePack>| {
assert_eq!(1, child_mailbox.tag_receive(&[Tag::special(64).unwrap()]));
assert_eq!(2, child_mailbox.tag_receive(&[Tag::special(65).unwrap()]));
assert_eq!(3, child_mailbox.tag_receive(&[Tag::special(66).unwrap()]));
parent.send(());
},
);
child.tag_send(Tag::special(66).unwrap(), 3);
child.tag_send(Tag::special(65).unwrap(), 2);
child.tag_send(Tag::special(64).unwrap(), 1);
let _ = mailbox.receive();
}
}