glider/proxy/protocol/smux/shaper_test.go

33 lines
599 B
Go
Raw Normal View History

2021-04-21 00:29:17 +08:00
package smux
import (
"container/heap"
"testing"
)
func TestShaper(t *testing.T) {
w1 := writeRequest{prio: 10}
w2 := writeRequest{prio: 10}
w3 := writeRequest{prio: 20}
w4 := writeRequest{prio: 100}
2021-09-22 22:49:33 +08:00
w5 := writeRequest{prio: (1 << 32) - 1}
2021-04-21 00:29:17 +08:00
var reqs shaperHeap
2021-09-22 22:49:33 +08:00
heap.Push(&reqs, w5)
2021-04-21 00:29:17 +08:00
heap.Push(&reqs, w4)
heap.Push(&reqs, w3)
heap.Push(&reqs, w2)
heap.Push(&reqs, w1)
2021-09-22 22:49:33 +08:00
var lastPrio = reqs[0].prio
2021-04-21 00:29:17 +08:00
for len(reqs) > 0 {
w := heap.Pop(&reqs).(writeRequest)
2021-09-22 22:49:33 +08:00
if int32(w.prio-lastPrio) < 0 {
2021-04-21 00:29:17 +08:00
t.Fatal("incorrect shaper priority")
}
t.Log("prio:", w.prio)
lastPrio = w.prio
}
}