| 83 | use rand::seq::SliceRandom; |
| 84 | #[flow_rs::rt::test] |
| 85 | async fn test_reorder() { |
| 86 | let reorder = Sandbox::pure("Reorder").unwrap(); |
| 87 | let input = reorder.input("inp").unwrap(); |
| 88 | let output = reorder.output("out").unwrap(); |
| 89 | let handle = reorder.start(); |
| 90 | let send_fut = async move { |
| 91 | let mut rng: StdRng = SeedableRng::from_entropy(); |
| 92 | let mut list: Vec<u64> = (0..10).collect(); |
| 93 | list[..].shuffle(&mut rng); |
| 94 | for i in list { |
| 95 | let mut envelope = Envelope::new(0usize).seal(); |
| 96 | envelope.info_mut().partial_id = Some(i); |
| 97 | input.send_any(envelope).await.ok(); |
| 98 | } |
| 99 | input.close(); |
| 100 | }; |
| 101 | |
| 102 | let recv_fut = async move { |
| 103 | let mut seq_id = 0; |
| 104 | while let Ok(msg) = output.recv_any().await { |
| 105 | assert_eq!(msg.info().partial_id, Some(seq_id)); |
| 106 | seq_id += 1; |
| 107 | } |
| 108 | }; |
| 109 | |
| 110 | join!(send_fut, recv_fut); |
| 111 | |
| 112 | handle.await.unwrap(); |
| 113 | } |
| 114 | } |