2020-08-11 18:52:13 +03:00
|
|
|
import sync
|
|
|
|
|
|
|
|
const (
|
|
|
|
queue_len = 1000
|
|
|
|
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()
|
|
|
|
go 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
|
|
|
}
|