25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

88 lines
1.9 KiB

  1. // Copyright 2014 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package http2
  5. import "testing"
  6. func TestFlow(t *testing.T) {
  7. var st flow
  8. var conn flow
  9. st.add(3)
  10. conn.add(2)
  11. if got, want := st.available(), int32(3); got != want {
  12. t.Errorf("available = %d; want %d", got, want)
  13. }
  14. st.setConnFlow(&conn)
  15. if got, want := st.available(), int32(2); got != want {
  16. t.Errorf("after parent setup, available = %d; want %d", got, want)
  17. }
  18. st.take(2)
  19. if got, want := conn.available(), int32(0); got != want {
  20. t.Errorf("after taking 2, conn = %d; want %d", got, want)
  21. }
  22. if got, want := st.available(), int32(0); got != want {
  23. t.Errorf("after taking 2, stream = %d; want %d", got, want)
  24. }
  25. }
  26. func TestFlowAdd(t *testing.T) {
  27. var f flow
  28. if !f.add(1) {
  29. t.Fatal("failed to add 1")
  30. }
  31. if !f.add(-1) {
  32. t.Fatal("failed to add -1")
  33. }
  34. if got, want := f.available(), int32(0); got != want {
  35. t.Fatalf("size = %d; want %d", got, want)
  36. }
  37. if !f.add(1<<31 - 1) {
  38. t.Fatal("failed to add 2^31-1")
  39. }
  40. if got, want := f.available(), int32(1<<31-1); got != want {
  41. t.Fatalf("size = %d; want %d", got, want)
  42. }
  43. if f.add(1) {
  44. t.Fatal("adding 1 to max shouldn't be allowed")
  45. }
  46. }
  47. func TestFlowAddOverflow(t *testing.T) {
  48. var f flow
  49. if !f.add(0) {
  50. t.Fatal("failed to add 0")
  51. }
  52. if !f.add(-1) {
  53. t.Fatal("failed to add -1")
  54. }
  55. if !f.add(0) {
  56. t.Fatal("failed to add 0")
  57. }
  58. if !f.add(1) {
  59. t.Fatal("failed to add 1")
  60. }
  61. if !f.add(1) {
  62. t.Fatal("failed to add 1")
  63. }
  64. if !f.add(0) {
  65. t.Fatal("failed to add 0")
  66. }
  67. if !f.add(-3) {
  68. t.Fatal("failed to add -3")
  69. }
  70. if got, want := f.available(), int32(-2); got != want {
  71. t.Fatalf("size = %d; want %d", got, want)
  72. }
  73. if !f.add(1<<31 - 1) {
  74. t.Fatal("failed to add 2^31-1")
  75. }
  76. if got, want := f.available(), int32(1+-3+(1<<31-1)); got != want {
  77. t.Fatalf("size = %d; want %d", got, want)
  78. }
  79. }