trpc.group/trpc-go/trpc-go@v1.0.3/pool/connpool/options_test.go (about)

     1  //
     2  //
     3  // Tencent is pleased to support the open source community by making tRPC available.
     4  //
     5  // Copyright (C) 2023 THL A29 Limited, a Tencent company.
     6  // All rights reserved.
     7  //
     8  // If you have downloaded a copy of the tRPC source code from Tencent,
     9  // please note that tRPC source code is licensed under the  Apache 2.0 License,
    10  // A copy of the Apache 2.0 License is included in this file.
    11  //
    12  //
    13  
    14  package connpool
    15  
    16  import (
    17  	"net"
    18  	"testing"
    19  	"time"
    20  
    21  	"github.com/stretchr/testify/assert"
    22  )
    23  
    24  func TestWithOptions(t *testing.T) {
    25  	opts := &Options{}
    26  	WithMinIdle(1)(opts)
    27  	WithMaxIdle(2)(opts)
    28  	WithMaxActive(10)(opts)
    29  	WithIdleTimeout(time.Second)(opts)
    30  	WithDialTimeout(time.Second)(opts)
    31  	WithMaxConnLifetime(time.Second * 60)(opts)
    32  	WithWait(true)(opts)
    33  	WithDialFunc(func(opts *DialOptions) (net.Conn, error) { return nil, nil })(opts)
    34  	WithHealthChecker(func(pc *PoolConn, isFast bool) bool { return true })(opts)
    35  	WithPushIdleConnToTail(true)(opts)
    36  
    37  	assert.Equal(t, opts.MinIdle, 1)
    38  	assert.Equal(t, opts.MaxIdle, 2)
    39  	assert.Equal(t, opts.MaxActive, 10)
    40  	assert.Equal(t, opts.IdleTimeout, time.Second)
    41  	assert.Equal(t, opts.DialTimeout, time.Second)
    42  	assert.Equal(t, opts.MaxConnLifetime, 60*time.Second)
    43  	assert.Equal(t, opts.Wait, true)
    44  	assert.NotNil(t, opts.Dial)
    45  	assert.NotNil(t, opts.Checker)
    46  	assert.Equal(t, opts.PushIdleConnToTail, true)
    47  
    48  }