-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_test.go
155 lines (131 loc) · 3.69 KB
/
main_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package main
import (
"io"
"log"
"os"
"strconv"
"sync"
"testing"
"time"
iceclient "github.com/ssetin/PenguinCast/src/client"
"github.com/ssetin/PenguinCast/src/ice"
)
var server *ice.Server
// ================================== Setup ========================================
const (
runServer = false
listenersCount = 5000 // total number of listeners
incStep = 50 // number of listeners, to increase with each step
waitStep = 5 // seconds between each step
secToListen = 5400 // seconds to listen by each connection
mountName = "RockRadio96"
hostAddr = "192.168.10.2:8008"
)
func init() {
if runServer {
go startServer()
time.Sleep(time.Second * 1)
}
log.Println("Waiting for SOURCE to connect...")
time.Sleep(time.Second * 5)
}
func startServer() {
server, err := ice.NewServer()
if err != nil {
log.Println(err.Error())
return
}
server.Start()
}
func TestMain(m *testing.M) {
runTests := m.Run()
if server != nil {
server.Close()
}
os.Exit(runTests)
}
// ================================== Tests ===========================================
func TestMonitoringListenersCount(b *testing.T) {
// run server in another process to monitor it separately from clients
log.Println("Start creating listeners...")
wg := &sync.WaitGroup{}
for i := 0; i < listenersCount/incStep; i++ {
wg.Add(incStep)
for k := 0; k < incStep; k++ {
go func(wg *sync.WaitGroup, i int) {
defer wg.Done()
time.Sleep(time.Millisecond * 200)
cl := &iceclient.PenguinClient{}
if i < 0 {
cl.Init(hostAddr, mountName, "dump/"+mountName+"."+strconv.Itoa(i)+".mp3")
} else {
cl.Init(hostAddr, mountName, "")
}
err := cl.Listen(secToListen)
if err != nil && err != io.EOF {
log.Println(err)
}
}(wg, i*incStep+k)
}
time.Sleep(time.Second * waitStep)
}
log.Println("Waiting for listeners to finito...")
wg.Wait()
}
func TestDump(b *testing.T) {
time.Sleep(time.Second * 5)
cl := &iceclient.PenguinClient{}
cl.Init(hostAddr, mountName, "dump/dump2.mp3")
cl.Listen(1)
}
// ================================== Benchmarks ===========================================
func BenchmarkGeneral(b *testing.B) {
cl := &iceclient.PenguinClient{}
cl.Init(hostAddr, mountName, "")
b.ResetTimer()
for i := 0; i < b.N; i++ {
err := cl.Listen(2)
if err != nil && err != io.EOF {
log.Println(err)
}
}
}
func BenchmarkParallel(b *testing.B) {
log.Println("Start creating listeners...")
wg := &sync.WaitGroup{}
for i := 0; i < 500/incStep; i++ {
wg.Add(incStep)
for k := 0; k < incStep; k++ {
go func(wg *sync.WaitGroup, i int) {
defer wg.Done()
time.Sleep(time.Millisecond * 100)
cl := &iceclient.PenguinClient{}
cl.Init(hostAddr, mountName, "")
err := cl.Listen(120)
if err != nil && err != io.EOF {
log.Println(err)
}
}(wg, i)
}
time.Sleep(time.Second * waitStep)
}
log.Println("Waiting for listeners to finito...")
wg.Wait()
}
func BenchmarkNone(b *testing.B) {
log.Println("Waiting for listeners...")
time.Sleep(time.Second * 800)
}
/*
go test -bench General -benchmem -benchtime 120s -cpuprofile=cpu.out -memprofile=mem.out main_test.go -run notests
go test -bench Parallel -race -benchmem -cpuprofile=cpu.out -memprofile=mem.out main_test.go -run notests
go test -bench None -benchmem -timeout 20m -cpuprofile=cpu.out -memprofile=mem.out main_test.go -run notests
go tool pprof main.test cpu.out
go tool pprof -alloc_objects main.test mem.out
go tool pprof main.test block.out
go test -v -run MonitoringListenersCount -timeout 150m main_test.go
go test -v -timeout 60s -run Dump main_test.go
go-torch main.test cpu.out
mp3check -e -a -S -T -E -v dump/*.mp3
ulimit -n 63000
*/