github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/net/http2/flow_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 "testing" 8 9 func TestFlow(t *testing.T) { 10 var st flow 11 var conn flow 12 st.add(3) 13 conn.add(2) 14 15 if got, want := st.available(), int32(3); got != want { 16 t.Errorf("available = %d; want %d", got, want) 17 } 18 st.setConnFlow(&conn) 19 if got, want := st.available(), int32(2); got != want { 20 t.Errorf("after parent setup, available = %d; want %d", got, want) 21 } 22 23 st.take(2) 24 if got, want := conn.available(), int32(0); got != want { 25 t.Errorf("after taking 2, conn = %d; want %d", got, want) 26 } 27 if got, want := st.available(), int32(0); got != want { 28 t.Errorf("after taking 2, stream = %d; want %d", got, want) 29 } 30 } 31 32 func TestFlowAdd(t *testing.T) { 33 var f flow 34 if !f.add(1) { 35 t.Fatal("failed to add 1") 36 } 37 if !f.add(-1) { 38 t.Fatal("failed to add -1") 39 } 40 if got, want := f.available(), int32(0); got != want { 41 t.Fatalf("size = %d; want %d", got, want) 42 } 43 if !f.add(1<<31 - 1) { 44 t.Fatal("failed to add 2^31-1") 45 } 46 if got, want := f.available(), int32(1<<31-1); got != want { 47 t.Fatalf("size = %d; want %d", got, want) 48 } 49 if f.add(1) { 50 t.Fatal("adding 1 to max shouldn't be allowed") 51 } 52 53 }