github.com/cloudwego/kitex@v0.9.0/pkg/remote/trans/nphttp2/grpc/bdp_estimator_test.go (about) 1 /* 2 * Copyright 2022 CloudWeGo Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package grpc 18 19 import ( 20 "testing" 21 22 "github.com/cloudwego/kitex/internal/test" 23 ) 24 25 func TestBdp(t *testing.T) { 26 // init bdp estimator 27 bdpEst := &bdpEstimator{ 28 bdp: initialWindowSize, 29 updateFlowControl: func(n uint32) {}, 30 } 31 size := 100 32 33 // mock data frame receive 34 sent := bdpEst.add(uint32(size)) 35 test.Assert(t, sent) 36 bdpEst.timesnap(bdpPing.data) 37 38 // receive normal ping 39 bdpEst.timesnap([8]byte{0, 0, 0, 0, 0, 0, 0, 0}) 40 41 // mock receiving data while bdp ping haven't been acked 42 for i := 0; i < 3; i++ { 43 sent = bdpEst.add(uint32(size)) 44 test.Assert(t, !sent) 45 } 46 47 // now bdp estimator receive ping ack and do calculation 48 bdpEst.calculate(bdpPing.data) 49 50 // receive normal ping 51 bdpEst.calculate([8]byte{0, 0, 0, 0, 0, 0, 0, 0}) 52 53 size = 10000 54 // calculate 15 times 55 for c := 0; c < 15; c++ { 56 sent = bdpEst.add(uint32(size)) 57 test.Assert(t, sent) 58 bdpEst.timesnap(bdpPing.data) 59 60 // mock the situation that network delay is very long and data is very big 61 for i := 0; i < 15; i++ { 62 sent = bdpEst.add(uint32(size)) 63 test.Assert(t, !sent) 64 } 65 66 // receive bdp ack and calculate again 67 bdpEst.calculate(bdpPing.data) 68 69 } 70 }