2020-08-11 18:52:13 +03:00
|
|
|
import sync
|
|
|
|
|
|
|
|
const (
|
2021-05-08 13:32:29 +03:00
|
|
|
queue_len = 1000
|
2020-08-11 18:52:13 +03:00
|
|
|
queue_fill = 763
|
|
|
|
)
|
|
|
|
|
2021-01-29 21:52:14 +03:00
|
|
|
fn do_send(ch chan int, mut fin sync.Semaphore) {
|
2020-08-11 18:52:13 +03:00
|
|
|
for i in 0 .. queue_fill {
|
2020-08-26 07:41:51 +03:00
|
|
|
ch <- i
|
2020-08-11 18:52:13 +03:00
|
|
|
}
|
|
|
|
fin.post()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_channel_len_cap() {
|
2020-08-26 07:41:51 +03:00
|
|
|
ch := chan int{cap: queue_len}
|
2021-01-29 21:52:14 +03:00
|
|
|
mut sem := sync.new_semaphore()
|
2022-11-05 10:46:40 +03:00
|
|
|
spawn do_send(ch, mut sem)
|
2020-08-11 18:52:13 +03:00
|
|
|
sem.wait()
|
|
|
|
assert ch.cap == queue_len
|
2020-08-26 07:41:51 +03:00
|
|
|
assert ch.len == queue_fill
|
2020-08-11 18:52:13 +03:00
|
|
|
}
|