mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-06 00:00:10 +02:00
sync: add loom test for mpsc (#903)
This patch updates tokio_sync::mpsc to support using loom for fuzz testing. It includes a basic fuzz test.
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
extern crate futures;
|
||||
#[macro_use]
|
||||
extern crate loom;
|
||||
|
||||
macro_rules! if_fuzz {
|
||||
($($t:tt)*) => {
|
||||
$($t)*
|
||||
}
|
||||
}
|
||||
|
||||
#[path = "../src/mpsc/mod.rs"]
|
||||
#[allow(warnings)]
|
||||
mod mpsc;
|
||||
|
||||
#[path = "../src/semaphore.rs"]
|
||||
#[allow(warnings)]
|
||||
mod semaphore;
|
||||
|
||||
use futures::{Stream, future::poll_fn};
|
||||
use loom::futures::block_on;
|
||||
use loom::thread;
|
||||
|
||||
#[test]
|
||||
fn closing_tx() {
|
||||
loom::fuzz(|| {
|
||||
let (mut tx, mut rx) = mpsc::channel(16);
|
||||
|
||||
thread::spawn(move || {
|
||||
tx.try_send(()).unwrap();
|
||||
drop(tx);
|
||||
});
|
||||
|
||||
let v = block_on(poll_fn(|| rx.poll())).unwrap();
|
||||
assert!(v.is_some());
|
||||
|
||||
let v = block_on(poll_fn(|| rx.poll())).unwrap();
|
||||
assert!(v.is_none());
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user