mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-16 16:41:20 +00:00
* Adds a random suffix to temporary Unix sockets during testing * Adds Unix domain socket tests for client (FAILING) This adds Unix domain socket tests for the privval client. Right now, one of the tests (TestRemoteSignerRetry) fails, probably because the Unix domain socket state is known instantaneously on both sides by the OS. Committing this to collaborate on the error. * Removes extraneous logging * Completes testing of Unix sockets client version This completes the testing of the client connecting via Unix sockets. There are two specific tests (TestSocketPVDeadline and TestRemoteSignerRetryTCPOnly) that are only relevant to TCP connections. * Renames test to show TCP-specificity * Adds testing into closures for consistency (forgot previously) * Moves test specific to RemoteSigner into own file As per discussion on #3132, `TestRemoteSignerRetryTCPOnly` doesn't really belong with the client tests. This moves it into its own file related to the `RemoteSigner` class.
69 lines
1.6 KiB
Go
69 lines
1.6 KiB
Go
package privval
|
|
|
|
import (
|
|
"net"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
|
cmn "github.com/tendermint/tendermint/libs/common"
|
|
"github.com/tendermint/tendermint/libs/log"
|
|
"github.com/tendermint/tendermint/types"
|
|
)
|
|
|
|
// TestRemoteSignerRetryTCPOnly will test connection retry attempts over TCP. We
|
|
// don't need this for Unix sockets because the OS instantly knows the state of
|
|
// both ends of the socket connection. This basically causes the
|
|
// RemoteSigner.dialer() call inside RemoteSigner.connect() to return
|
|
// successfully immediately, putting an instant stop to any retry attempts.
|
|
func TestRemoteSignerRetryTCPOnly(t *testing.T) {
|
|
var (
|
|
attemptc = make(chan int)
|
|
retries = 2
|
|
)
|
|
|
|
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
|
require.NoError(t, err)
|
|
|
|
go func(ln net.Listener, attemptc chan<- int) {
|
|
attempts := 0
|
|
|
|
for {
|
|
conn, err := ln.Accept()
|
|
require.NoError(t, err)
|
|
|
|
err = conn.Close()
|
|
require.NoError(t, err)
|
|
|
|
attempts++
|
|
|
|
if attempts == retries {
|
|
attemptc <- attempts
|
|
break
|
|
}
|
|
}
|
|
}(ln, attemptc)
|
|
|
|
rs := NewRemoteSigner(
|
|
log.TestingLogger(),
|
|
cmn.RandStr(12),
|
|
types.NewMockPV(),
|
|
DialTCPFn(ln.Addr().String(), testConnDeadline, ed25519.GenPrivKey()),
|
|
)
|
|
defer rs.Stop()
|
|
|
|
RemoteSignerConnDeadline(time.Millisecond)(rs)
|
|
RemoteSignerConnRetries(retries)(rs)
|
|
|
|
assert.Equal(t, rs.Start(), ErrDialRetryMax)
|
|
|
|
select {
|
|
case attempts := <-attemptc:
|
|
assert.Equal(t, retries, attempts)
|
|
case <-time.After(100 * time.Millisecond):
|
|
t.Error("expected remote to observe connection attempts")
|
|
}
|
|
}
|