forked from mkieweg/minq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheduler_test.go
106 lines (96 loc) · 1.71 KB
/
scheduler_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
package minq
import (
"testing"
"net"
"strconv"
"fmt"
"sync"
"time"
)
func TestSchedulingAlgorithm(t *testing.T) {
results := make(map[*Path]int)
pathIds := make([]uint32,0)
ah := NewAddressHelper()
/*
local,err := net.ResolveUDPAddr("udp", "127.0.0.1:44333")
if err != nil{
log.Println(err)
return
}
remote,err := net.ResolveUDPAddr("udp", "127.0.0.2:44333")
if err != nil{
log.Println(err)
return
}
usock, err := ah.openSocket(local)
if err != nil {
log.Println(err)
return
}
initTrans := NewUdpTransport(usock, remote)
pathZero := Path{
nil,
true,
initTrans,
0,
1000,
0,
nil,
nil,
}
*/
conn := Connection{
}
conn.log = newConnectionLogger(&conn)
scheduler := Scheduler{
make(map[uint32]*Path),
&conn,
0,
nil,
pathIds,
0,
ah,
make(chan string),
nil,
nil,
make(map[string]*net.UDPAddr),
sync.RWMutex{},
sync.RWMutex{},
false,
1000,
}
for i := 0; i < 10; i++ {
j := i + 1
local,err := net.ResolveUDPAddr("udp", "127.0.0.1:443" + strconv.Itoa(j))
if err != nil{
fmt.Println(err)
return
}
remote,err := net.ResolveUDPAddr("udp", "127.0.0.1:442" + strconv.Itoa(j))
if err != nil{
fmt.Println(err)
return
}
scheduler.newPath(local, remote)
}
fmt.Println("Created Paths")
for k := 0; k < 100000 ; k++ {
path,err := scheduler.weightedSelect()
if err != nil {
fmt.Println(err)
return
}
results[path]++
}
fmt.Println("Selected Paths")
time.Sleep(100 * time.Millisecond)
for path,amount := range results{
fmt.Println("Path: ", path.GetPathID())
fmt.Println("\tWeight: ", path.GetWeight())
fmt.Println("\tCount: ", amount)
}
for _,socket := range ah.sockets {
socket.Close()
}
fmt.Println("Test finished")
}