trpc.group/trpc-go/trpc-go@v1.0.3/internal/reuseport/tcp_linux_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  //go:build linux
    15  // +build linux
    16  
    17  package reuseport
    18  
    19  import (
    20  	"syscall"
    21  	"testing"
    22  
    23  	"github.com/stretchr/testify/assert"
    24  )
    25  
    26  func TestMaxListenerBackLog(t *testing.T) {
    27  	oldMaxConnFileName := maxConnFileName
    28  	defer func() {
    29  		maxConnFileName = oldMaxConnFileName
    30  	}()
    31  
    32  	tests := []struct {
    33  		name     string
    34  		fileName string
    35  		want     int
    36  	}{
    37  		{
    38  			name:     "file not exist",
    39  			fileName: "./testdata/NotExistFile.txt",
    40  			want:     syscall.SOMAXCONN,
    41  		},
    42  		{
    43  			name:     "file content invalid, no eof",
    44  			fileName: "./testdata/NoEof.txt",
    45  			want:     syscall.SOMAXCONN,
    46  		},
    47  		{
    48  			name:     "empty line",
    49  			fileName: "./testdata/EmptyLine.txt",
    50  			want:     syscall.SOMAXCONN,
    51  		},
    52  		{
    53  			name:     "num zero",
    54  			fileName: "./testdata/NumZero.txt",
    55  			want:     syscall.SOMAXCONN,
    56  		},
    57  		{
    58  			name:     "num 65536",
    59  			fileName: "./testdata/NumMax.txt",
    60  			want:     65535,
    61  		},
    62  	}
    63  
    64  	for _, tt := range tests {
    65  		t.Run(tt.name, func(t *testing.T) {
    66  			maxConnFileName = tt.fileName
    67  			assert.Equalf(t, tt.want, maxListenerBacklog(), "maxListenerBacklog()")
    68  		})
    69  	}
    70  }