Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #83: thingbuf hangs when buffer is full #85

Merged
merged 7 commits into from
Apr 18, 2024
35 changes: 34 additions & 1 deletion src/mpsc/tests/mpsc_blocking.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;
use crate::loom::{self, alloc::Track, thread};
use crate::mpsc::blocking;
use crate::mpsc::blocking::RecvRef;
use crate::mpsc::{blocking, errors};

#[test]
#[cfg_attr(ci_skip_slow_models, ignore)]
Expand Down Expand Up @@ -452,3 +452,36 @@ fn tx_close_drains_queue() {
producer.join().unwrap();
});
}

#[test]
fn test_full() {
hawkw marked this conversation as resolved.
Show resolved Hide resolved
loom::model(|| {
let (tx, rx) = channel(4);
let p1 = {
let tx = tx.clone();
thread::spawn(move || loop {
match tx.try_send(1) {
Ok(_) => {}
Err(errors::TrySendError::Full(_)) => break,
Err(err) => assert!(false, "unexpected error: {:?}", err),
}
thread::yield_now();
})
};

let p2 = {
let tx = tx.clone();
thread::spawn(move || loop {
match tx.try_send(2) {
Ok(_) => {}
Err(errors::TrySendError::Full(_)) => break,
Err(err) => assert!(false, "unexpected error: {:?}", err),
}
thread::yield_now();
})
};

p1.join().unwrap();
p2.join().unwrap();
});
}
Loading