blob: 72a11fb0d588ac281403f33fa220ef95397b9fbb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
package utilities
import (
"sync"
"testing"
"time"
)
func TestReadAfterCloseOnBufferedChannel(t *testing.T) {
communication := make(chan int, 100)
maxC := 0
wg := sync.WaitGroup{}
wg.Add(2)
go func() {
counter := 0
for range make([]int, 50) {
communication <- counter
counter++
}
close(communication)
wg.Done()
}()
go func() {
time.Sleep(2 * time.Second)
for c := range communication {
maxC = c
}
wg.Done()
}()
wg.Wait()
if maxC != 49 {
t.Fatalf("Did not read all sent items from a buffered channel after channel.")
}
}
|