~trn/gfsmux

ref: 552547081df14ae563f5c8a8e52cad483fe581da gfsmux/shaper_test.go -rw-r--r-- 720 bytes
55254708 — Jeffrey H. Johnson Update dependencies 4 months ago
                                                                                
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
package gfsmux_test

import (
	"container/heap"
	"testing"

	smux "github.com/johnsonjh/gfsmux"
	u "github.com/johnsonjh/leaktestfe"
)

func TestShaper(
	t *testing.T,
) {
	defer u.Leakplug(
		t,
	)
	w1 := smux.WriteRequest{Prio: 10}
	w2 := smux.WriteRequest{Prio: 10}
	w3 := smux.WriteRequest{Prio: 20}
	w4 := smux.WriteRequest{Prio: 100}

	var reqs smux.ShaperHeap
	heap.Push(
		&reqs,
		w4,
	)
	heap.Push(
		&reqs,
		w3,
	)
	heap.Push(
		&reqs,
		w2,
	)
	heap.Push(
		&reqs,
		w1,
	)

	var lastPrio uint64
	for len(
		reqs,
	) > 0 {
		w := heap.Pop(&reqs).(smux.WriteRequest)
		if w.Prio < lastPrio {
			t.Fatal(
				"incorrect shaper priority",
			)
		}

		t.Log(
			"Prio:",
			w.Prio,
		)
		lastPrio = w.Prio
	}
}