-
Notifications
You must be signed in to change notification settings - Fork 53
/
poll_test.go
70 lines (63 loc) · 1.26 KB
/
poll_test.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package srtgo
import (
"testing"
)
func connectLoop(port uint16, semChan chan struct{}) {
for {
//fmt.Printf("Connecting\n")
s := NewSrtSocket("127.0.0.1", port, map[string]string{"blocking": "0", "mode": "caller"})
err := s.Connect()
if err != nil {
continue
}
s.Close()
_, ok := <-semChan
if !ok {
return
}
}
}
func benchAccept(blocking string, N int) {
start:
port := randomPort()
s := NewSrtSocket("127.0.0.1", port, map[string]string{"blocking": blocking, "mode": "listener"})
if s == nil {
goto start
}
if err := s.Listen(5); err != nil {
goto start
}
semChan := make(chan struct{}, 8)
go connectLoop(port, semChan)
semChan <- struct{}{}
semChan <- struct{}{}
for i := 0; i < N; i++ {
semChan <- struct{}{}
_, _, _ = s.Accept()
}
close(semChan)
s.Close()
}
func BenchmarkAcceptBlocking(b *testing.B) {
benchAccept("1", b.N)
}
func BenchmarkAcceptNonBlocking(b *testing.B) {
benchAccept("0", b.N)
}
/*
func BenchmarkAcceptNonBlockingParallel(b *testing.B) {
SrtSetLogLevel(SrtLogLevelCrit)
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
benchAccept("0", 2)
}
})
}
func BenchmarkAcceptBlockingParallel(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
benchAccept("1", 2)
}
})
}
*/