| 1 | const num_iterations = 10000 |
| 2 | |
| 3 | fn do_send(ch chan int) { |
| 4 | for i in 0 .. num_iterations { |
| 5 | ch <- i |
| 6 | } |
| 7 | } |
| 8 | |
| 9 | fn test_channel_unbuffered() { |
| 10 | ch := chan int{} |
| 11 | spawn do_send(ch) |
| 12 | mut sum := i64(0) |
| 13 | for _ in 0 .. num_iterations { |
| 14 | sum += <-ch |
| 15 | } |
| 16 | assert sum == u64(num_iterations) * (num_iterations - 1) / 2 |
| 17 | } |
| 18 |