trpc.group/trpc-go/trpc-go@v1.0.3/transport/tnet/multiplex/statemutex_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 || freebsd || dragonfly || darwin
    15  // +build linux freebsd dragonfly darwin
    16  
    17  package multiplex
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/stretchr/testify/require"
    23  )
    24  
    25  func TestStateRWMutex(t *testing.T) {
    26  	var mu stateRWMutex
    27  	require.True(t, mu.rLock())
    28  	mu.rUnlock()
    29  
    30  	require.True(t, mu.lock())
    31  	mu.closeLocked()
    32  	mu.unlock()
    33  
    34  	// Lock return false when mutex is already closed.
    35  	require.False(t, mu.rLock())
    36  	require.False(t, mu.lock())
    37  }