github.com/cloudwego/kitex@v0.9.0/pkg/connpool/config_test.go (about) 1 /* 2 * Copyright 2021 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 connpool 18 19 import ( 20 "testing" 21 "time" 22 23 "github.com/cloudwego/kitex/internal/test" 24 ) 25 26 func TestCheckPoolConfig(t *testing.T) { 27 cfg := CheckPoolConfig(IdleConfig{MaxIdleTimeout: 0}) 28 test.Assert(t, cfg.MaxIdleTimeout == defaultMaxIdleTimeout) 29 cfg = CheckPoolConfig(IdleConfig{MaxIdleTimeout: time.Millisecond}) 30 test.Assert(t, cfg.MaxIdleTimeout == minMaxIdleTimeout) 31 32 // minIdle 33 cfg = CheckPoolConfig(IdleConfig{MinIdlePerAddress: -1}) 34 test.Assert(t, cfg.MinIdlePerAddress == 0) 35 test.Assert(t, cfg.MaxIdlePerAddress == 1) 36 test.Assert(t, cfg.MaxIdleGlobal == defaultMaxIdleGlobal) 37 cfg = CheckPoolConfig(IdleConfig{MinIdlePerAddress: 1}) 38 test.Assert(t, cfg.MinIdlePerAddress == 1) 39 cfg = CheckPoolConfig(IdleConfig{MinIdlePerAddress: maxMinIdlePerAddress + 1}) 40 test.Assert(t, cfg.MinIdlePerAddress == maxMinIdlePerAddress) 41 42 // maxIdle 43 cfg = CheckPoolConfig(IdleConfig{MaxIdlePerAddress: 1, MinIdlePerAddress: 2}) 44 test.Assert(t, cfg.MaxIdlePerAddress == 2) 45 cfg = CheckPoolConfig(IdleConfig{MaxIdlePerAddress: -1}) 46 test.Assert(t, cfg.MaxIdlePerAddress == 1) 47 48 // maxIdleGlobal 49 cfg = CheckPoolConfig(IdleConfig{MaxIdleGlobal: 9, MaxIdlePerAddress: 10, MinIdlePerAddress: 1}) 50 test.Assert(t, cfg.MaxIdleGlobal == 10) 51 }