v / vlib / sync / channel_fill_test.v
20 lines · 17 sloc · 358 bytes · f09826e928f9612bab9299faefff7cf34a503362
Raw
1import sync
2
3const queue_len = 1000
4const queue_fill = 763
5
6fn do_send(ch chan int, mut fin sync.Semaphore) {
7 for i in 0 .. queue_fill {
8 ch <- i
9 }
10 fin.post()
11}
12
13fn test_channel_len_cap() {
14 ch := chan int{cap: queue_len}
15 mut sem := sync.new_semaphore()
16 spawn do_send(ch, mut sem)
17 sem.wait()
18 assert ch.cap == queue_len
19 assert ch.len == queue_fill
20}
21