Advertisement
NLinker

Mailbox test

Dec 18th, 2019
1,449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.84 KB | None | 0 0
  1. #[cfg(test)]
  2. mod tests {
  3.     use super::*;
  4.     use std::fs;
  5.     use tempdir::TempDir;
  6.  
  7.     #[tokio::test]
  8.     async fn test_mailbox_senders() -> Result<(), Box<dyn std::error::Error>> {
  9.         let tmp_dir = TempDir::new("test_mailbox")?;
  10.         let address = tmp_dir.path().join("test_message_1");
  11.         let mut mailbox_sender = MailboxSenders::default();
  12.         let (tx, fut) = mailbox_sender.create(address.clone());
  13.         tx.unbounded_send("foo\n".into())?;
  14.         mailbox_sender
  15.             .get(&address)
  16.             .unwrap()
  17.             .unbounded_send("bar".into())?;
  18.         tx.unbounded_send("baz\n".into())?;
  19.         mailbox_sender.remove(&address);
  20.         drop(tx);
  21.         fut.await?;
  22.         let contents = fs::read_to_string(&address).unwrap();
  23.         assert_eq!(contents, "foo\nbar\nbaz\n");
  24.         Ok(())
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement