Skip to content

Commit b7029cf

Browse files
committed
Port test from golang/goroutines.
1 parent 240cf90 commit b7029cf

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

crossbeam-channel/tests/golang.rs

+36
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,42 @@ mod fifo {
314314
}
315315
}
316316

317+
// https://github.com/golang/go/blob/master/test/chan/goroutines.go
318+
mod goroutines {
319+
use super::*;
320+
321+
fn f(left: Chan<i32>, right: Chan<i32>) {
322+
left.send(right.recv().unwrap());
323+
}
324+
325+
#[test]
326+
fn main() {
327+
let mut n = 10_000i32;
328+
if ::std::env::args().count() > 1 {
329+
n = match i32::from_str_radix(::std::env::args().nth(1).unwrap().as_ref(), 10) {
330+
Ok(n) => n,
331+
Err(_) => {
332+
println!("bad arg");
333+
::std::process::exit(1);
334+
}
335+
};
336+
}
337+
338+
let leftmost = make::<i32>(0);
339+
let mut right = leftmost.clone();
340+
let mut left = leftmost.clone();
341+
342+
for _ in 0..n {
343+
right = make::<i32>(0);
344+
go!(left, right, f(left, right));
345+
left = right.clone();
346+
}
347+
348+
go!(right, right.send(1));
349+
leftmost.recv().unwrap();
350+
}
351+
}
352+
317353
// https://github.com/golang/go/blob/master/test/chan/nonblock.go
318354
mod nonblock {
319355
use super::*;

0 commit comments

Comments
 (0)