Port test from golang/goroutines.
@@ -314,6 +314,42 @@ mod fifo {
}
}
+// https://github.com/golang/go/blob/master/test/chan/goroutines.go
+mod goroutines {
+ use super::*;
+
+ fn f(left: Chan<i32>, right: Chan<i32>) {
+ left.send(right.recv().unwrap());
+ }
+
+ #[test]
+ fn main() {
+ let mut n = 10_000i32;
+ if ::std::env::args().count() > 1 {
+ n = match i32::from_str_radix(::std::env::args().nth(1).unwrap().as_ref(), 10) {
+ Ok(n) => n,
+ Err(_) => {
+ println!("bad arg");
+ ::std::process::exit(1);
+ }
+ };
+ }
+
+ let leftmost = make::<i32>(0);
+ let mut right = leftmost.clone();
+ let mut left = leftmost.clone();
+
+ for _ in 0..n {
+ right = make::<i32>(0);
+ go!(left, right, f(left, right));
+ left = right.clone();
+ }
+
+ go!(right, right.send(1));
+ leftmost.recv().unwrap();
+ }
+}
+
// https://github.com/golang/go/blob/master/test/chan/nonblock.go
mod nonblock {
use super::*;
