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