2020-08-11 17:52:13 +02:00
|
|
|
import sync
|
|
|
|
|
|
|
|
const (
|
|
|
|
queue_len = 1000
|
|
|
|
queue_fill = 763
|
|
|
|
)
|
|
|
|
|
2020-08-26 06:41:51 +02:00
|
|
|
fn do_send(ch chan int, fin sync.Semaphore) {
|
2020-08-11 17:52:13 +02:00
|
|
|
for i in 0 .. queue_fill {
|
2020-08-26 06:41:51 +02:00
|
|
|
ch <- i
|
2020-08-11 17:52:13 +02:00
|
|
|
}
|
|
|
|
fin.post()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_channel_len_cap() {
|
2020-08-26 06:41:51 +02:00
|
|
|
ch := chan int{cap: queue_len}
|
2020-08-11 17:52:13 +02:00
|
|
|
sem := sync.new_semaphore()
|
2020-08-26 06:41:51 +02:00
|
|
|
go do_send(ch, sem)
|
2020-08-11 17:52:13 +02:00
|
|
|
sem.wait()
|
|
|
|
assert ch.cap == queue_len
|
2020-08-26 06:41:51 +02:00
|
|
|
assert ch.len == queue_fill
|
2020-08-11 17:52:13 +02:00
|
|
|
}
|