Skip to content

Commit 9c31495

Browse files
committed
add shaper test
1 parent 6284957 commit 9c31495

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

shaper_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package smux
2+
3+
import (
4+
"container/heap"
5+
"testing"
6+
)
7+
8+
func TestShaper(t *testing.T) {
9+
w1 := writeRequest{prio: 10}
10+
w2 := writeRequest{prio: 10}
11+
w3 := writeRequest{prio: 20}
12+
w4 := writeRequest{prio: 100}
13+
14+
var reqs shaperHeap
15+
heap.Push(&reqs, w4)
16+
heap.Push(&reqs, w3)
17+
heap.Push(&reqs, w2)
18+
heap.Push(&reqs, w1)
19+
20+
var lastPrio uint64
21+
for len(reqs) > 0 {
22+
w := heap.Pop(&reqs).(writeRequest)
23+
if w.prio < lastPrio {
24+
t.Fatal("incorrect shaper priority")
25+
}
26+
27+
t.Log("prio:", w.prio)
28+
lastPrio = w.prio
29+
}
30+
}

0 commit comments

Comments
 (0)