shaper_test.go 720 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package gfsmux_test
  2. import (
  3. "container/heap"
  4. "testing"
  5. smux "github.com/johnsonjh/gfsmux"
  6. u "github.com/johnsonjh/leaktestfe"
  7. )
  8. func TestShaper(
  9. t *testing.T,
  10. ) {
  11. defer u.Leakplug(
  12. t,
  13. )
  14. w1 := smux.WriteRequest{Prio: 10}
  15. w2 := smux.WriteRequest{Prio: 10}
  16. w3 := smux.WriteRequest{Prio: 20}
  17. w4 := smux.WriteRequest{Prio: 100}
  18. var reqs smux.ShaperHeap
  19. heap.Push(
  20. &reqs,
  21. w4,
  22. )
  23. heap.Push(
  24. &reqs,
  25. w3,
  26. )
  27. heap.Push(
  28. &reqs,
  29. w2,
  30. )
  31. heap.Push(
  32. &reqs,
  33. w1,
  34. )
  35. var lastPrio uint64
  36. for len(
  37. reqs,
  38. ) > 0 {
  39. w := heap.Pop(&reqs).(smux.WriteRequest)
  40. if w.Prio < lastPrio {
  41. t.Fatal(
  42. "incorrect shaper priority",
  43. )
  44. }
  45. t.Log(
  46. "Prio:",
  47. w.Prio,
  48. )
  49. lastPrio = w.Prio
  50. }
  51. }