diff options
| author | Lzu Tao <taolzu@gmail.com> | 2020-08-27 13:45:01 +0000 |
|---|---|---|
| committer | Lzu Tao <taolzu@gmail.com> | 2020-08-31 02:56:59 +0000 |
| commit | a4e926daeeaedc9178846711daf1f4cb6ce505fb (patch) | |
| tree | 0c830f716f6f5ad17736d459f5de9b9199006d54 /library/std/src/sync/mpsc/mpsc_queue | |
| parent | db6cbfc49ca655739ba8caae43ebd7c77c8a1179 (diff) | |
| download | rust-a4e926daeeaedc9178846711daf1f4cb6ce505fb.tar.gz rust-a4e926daeeaedc9178846711daf1f4cb6ce505fb.zip | |
std: move "mod tests/benches" to separate files
Also doing fmt inplace as requested.
Diffstat (limited to 'library/std/src/sync/mpsc/mpsc_queue')
| -rw-r--r-- | library/std/src/sync/mpsc/mpsc_queue/tests.rs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/library/std/src/sync/mpsc/mpsc_queue/tests.rs b/library/std/src/sync/mpsc/mpsc_queue/tests.rs new file mode 100644 index 00000000000..348b83424b0 --- /dev/null +++ b/library/std/src/sync/mpsc/mpsc_queue/tests.rs @@ -0,0 +1,47 @@ +use super::{Data, Empty, Inconsistent, Queue}; +use crate::sync::mpsc::channel; +use crate::sync::Arc; +use crate::thread; + +#[test] +fn test_full() { + let q: Queue<Box<_>> = Queue::new(); + q.push(box 1); + q.push(box 2); +} + +#[test] +fn test() { + let nthreads = 8; + let nmsgs = 1000; + let q = Queue::new(); + match q.pop() { + Empty => {} + Inconsistent | Data(..) => panic!(), + } + let (tx, rx) = channel(); + let q = Arc::new(q); + + for _ in 0..nthreads { + let tx = tx.clone(); + let q = q.clone(); + thread::spawn(move || { + for i in 0..nmsgs { + q.push(i); + } + tx.send(()).unwrap(); + }); + } + + let mut i = 0; + while i < nthreads * nmsgs { + match q.pop() { + Empty | Inconsistent => {} + Data(_) => i += 1, + } + } + drop(tx); + for _ in 0..nthreads { + rx.recv().unwrap(); + } +} |
