github.com/DFWallet/tendermint-cosmos@v0.0.2/privval/socket_dialers_test.go (about)

     1  package privval
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  	"github.com/stretchr/testify/require"
    10  
    11  	"github.com/DFWallet/tendermint-cosmos/crypto/ed25519"
    12  )
    13  
    14  func getDialerTestCases(t *testing.T) []dialerTestCase {
    15  	tcpAddr := GetFreeLocalhostAddrPort()
    16  	unixFilePath, err := testUnixAddr()
    17  	require.NoError(t, err)
    18  	unixAddr := fmt.Sprintf("unix://%s", unixFilePath)
    19  
    20  	return []dialerTestCase{
    21  		{
    22  			addr:   tcpAddr,
    23  			dialer: DialTCPFn(tcpAddr, testTimeoutReadWrite, ed25519.GenPrivKey()),
    24  		},
    25  		{
    26  			addr:   unixAddr,
    27  			dialer: DialUnixFn(unixFilePath),
    28  		},
    29  	}
    30  }
    31  
    32  func TestIsConnTimeoutForFundamentalTimeouts(t *testing.T) {
    33  	// Generate a networking timeout
    34  	tcpAddr := GetFreeLocalhostAddrPort()
    35  	dialer := DialTCPFn(tcpAddr, time.Millisecond, ed25519.GenPrivKey())
    36  	_, err := dialer()
    37  	assert.Error(t, err)
    38  	assert.True(t, IsConnTimeout(err))
    39  }
    40  
    41  func TestIsConnTimeoutForWrappedConnTimeouts(t *testing.T) {
    42  	tcpAddr := GetFreeLocalhostAddrPort()
    43  	dialer := DialTCPFn(tcpAddr, time.Millisecond, ed25519.GenPrivKey())
    44  	_, err := dialer()
    45  	assert.Error(t, err)
    46  	err = fmt.Errorf("%v: %w", err, ErrConnectionTimeout)
    47  	assert.True(t, IsConnTimeout(err))
    48  }