github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/net/http2/priority_test.go (about) 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 5 package http2 6 7 import ( 8 "testing" 9 ) 10 11 func TestPriority(t *testing.T) { 12 // A -> B 13 // move A's parent to B 14 streams := make(map[uint32]*stream) 15 a := &stream{ 16 parent: nil, 17 weight: 16, 18 } 19 streams[1] = a 20 b := &stream{ 21 parent: a, 22 weight: 16, 23 } 24 streams[2] = b 25 adjustStreamPriority(streams, 1, PriorityParam{ 26 Weight: 20, 27 StreamDep: 2, 28 }) 29 if a.parent != b { 30 t.Errorf("Expected A's parent to be B") 31 } 32 if a.weight != 20 { 33 t.Errorf("Expected A's weight to be 20; got %d", a.weight) 34 } 35 if b.parent != nil { 36 t.Errorf("Expected B to have no parent") 37 } 38 if b.weight != 16 { 39 t.Errorf("Expected B's weight to be 16; got %d", b.weight) 40 } 41 } 42 43 func TestPriorityExclusiveZero(t *testing.T) { 44 // A B and C are all children of the 0 stream. 45 // Exclusive reprioritization to any of the streams 46 // should bring the rest of the streams under the 47 // reprioritized stream 48 streams := make(map[uint32]*stream) 49 a := &stream{ 50 parent: nil, 51 weight: 16, 52 } 53 streams[1] = a 54 b := &stream{ 55 parent: nil, 56 weight: 16, 57 } 58 streams[2] = b 59 c := &stream{ 60 parent: nil, 61 weight: 16, 62 } 63 streams[3] = c 64 adjustStreamPriority(streams, 3, PriorityParam{ 65 Weight: 20, 66 StreamDep: 0, 67 Exclusive: true, 68 }) 69 if a.parent != c { 70 t.Errorf("Expected A's parent to be C") 71 } 72 if a.weight != 16 { 73 t.Errorf("Expected A's weight to be 16; got %d", a.weight) 74 } 75 if b.parent != c { 76 t.Errorf("Expected B's parent to be C") 77 } 78 if b.weight != 16 { 79 t.Errorf("Expected B's weight to be 16; got %d", b.weight) 80 } 81 if c.parent != nil { 82 t.Errorf("Expected C to have no parent") 83 } 84 if c.weight != 20 { 85 t.Errorf("Expected C's weight to be 20; got %d", b.weight) 86 } 87 } 88 89 func TestPriorityOwnParent(t *testing.T) { 90 streams := make(map[uint32]*stream) 91 a := &stream{ 92 parent: nil, 93 weight: 16, 94 } 95 streams[1] = a 96 b := &stream{ 97 parent: a, 98 weight: 16, 99 } 100 streams[2] = b 101 adjustStreamPriority(streams, 1, PriorityParam{ 102 Weight: 20, 103 StreamDep: 1, 104 }) 105 if a.parent != nil { 106 t.Errorf("Expected A's parent to be nil") 107 } 108 if a.weight != 20 { 109 t.Errorf("Expected A's weight to be 20; got %d", a.weight) 110 } 111 if b.parent != a { 112 t.Errorf("Expected B's parent to be A") 113 } 114 if b.weight != 16 { 115 t.Errorf("Expected B's weight to be 16; got %d", b.weight) 116 } 117 118 }