forked from tevino/tcp-shaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
result_pipes_linux_test.go
85 lines (69 loc) · 1.74 KB
/
result_pipes_linux_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package tcp
import (
"context"
"runtime"
"testing"
"time"
)
func _newChecker(b *testing.B) (*Checker, context.CancelFunc) {
c := NewChecker()
ctx, cancel := context.WithCancel(context.Background())
go c.CheckingLoop(ctx)
select {
case <-time.After(time.Second):
b.FailNow()
case <-c.WaitReady():
}
return c, cancel
}
func _benchmarkChecker(b *testing.B, c *Checker, addr string) {
b.SetParallelism(runtime.NumCPU() * 10)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
// if timeout >= 1s, this func will run only once in the benchmark.
c.CheckAddr(addr, time.Millisecond*900)
}
})
b.StopTimer()
}
func BenchmarkResultPipesMUOK(b *testing.B) {
c, cancel := _newChecker(b)
defer cancel()
c.resultPipes = newResultPipesMU()
addr, stop := _startTestServer()
defer stop()
_benchmarkChecker(b, c, addr)
}
func BenchmarkResultPipesSyncMapOK(b *testing.B) {
c, cancel := _newChecker(b)
defer cancel()
c.resultPipes = newResultPipesSyncMap()
addr, stop := _startTestServer()
defer stop()
_benchmarkChecker(b, c, addr)
}
func BenchmarkResultPipesMUErr(b *testing.B) {
c, cancel := _newChecker(b)
defer cancel()
c.resultPipes = newResultPipesMU()
_benchmarkChecker(b, c, AddrDead)
}
func BenchmarkResultPipesSyncMapErr(b *testing.B) {
c, cancel := _newChecker(b)
defer cancel()
c.resultPipes = newResultPipesSyncMap()
_benchmarkChecker(b, c, AddrDead)
}
func BenchmarkResultPipesMUTimeout(b *testing.B) {
c, cancel := _newChecker(b)
defer cancel()
c.resultPipes = newResultPipesMU()
_benchmarkChecker(b, c, AddrTimeout)
}
func BenchmarkResultPipesSyncMapTimeout(b *testing.B) {
c, cancel := _newChecker(b)
defer cancel()
c.resultPipes = newResultPipesSyncMap()
_benchmarkChecker(b, c, AddrTimeout)
}