MCPcopy Create free account
hub / github.com/aws/clock-bound / concurrent_send_receive

Function concurrent_send_receive

clock-bound/src/daemon/async_ring_buffer.rs:356–383  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

354
355 #[tokio::test]
356 async fn concurrent_send_receive() {
357 let (tx, rx) = create(3);
358 let tx_notified = Arc::new(Notify::new());
359 let rx_notified = Arc::clone(&tx_notified);
360
361 let handle = tokio::spawn(async move {
362 for i in 0..5 {
363 tx.send(i).unwrap();
364 tx_notified.notified().await;
365 }
366 });
367
368 let mut received = Vec::new();
369 for _ in 0..5 {
370 if let Ok(value) = rx.recv().await {
371 received.push(value);
372 rx_notified.notify_one();
373 }
374 }
375
376 assert_eq!(received.len(), 5);
377 // Check that values are in sequence (though not necessarily starting from 0
378 // due to potential overwrites)
379 for i in 1..received.len() {
380 assert_eq!(received[i], i);
381 }
382 handle.await.unwrap();
383 }
384
385 #[tokio::test]
386 async fn cancel_safety() {

Callers

nothing calls this directly

Calls 6

createFunction · 0.85
sendMethod · 0.80
newFunction · 0.50
recvMethod · 0.45
pushMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected