fix non deterministic test failures and race in privval socket (#3258)

* node: decrease retry conn timeout in test

Should fix #3256

The retry timeout was set to the default, which is the same as the
accept timeout, so it's no wonder this would fail. Here we decrease the
retry timeout so we can try many times before the accept timeout.

* p2p: increase handshake timeout in test

This fails sometimes, presumably because the handshake timeout is so low
(only 50ms). So increase it to 1s. Should fix #3187

* privval: fix race with ping. closes #3237

Pings happen in a go-routine and can happen concurrently with other
messages. Since we use a request/response protocol, we expect to send a
request and get back the corresponding response. But with pings
happening concurrently, this assumption could be violated. We were using
a mutex, but only a RWMutex, where the RLock was being held for sending
messages - this was to allow the underlying connection to be replaced if
it fails. Turns out we actually need to use a full lock (not just a read
lock) to prevent multiple requests from happening concurrently.

* node: fix test name. DelayedStop -> DelayedStart

* autofile: Wait() method

In the TestWALTruncate in consensus/wal_test.go we remove the WAL
directory at the end of the test. However the wal.Stop() does not
properly wait for the autofile group to finish shutting down. Hence it
was possible that the group's go-routine is still running when the
cleanup happens, which causes a panic since the directory disappeared.
Here we add a Wait() method to properly wait until the go-routine exits
so we can safely clean up. This fixes #2852.
This commit is contained in:
Ethan Buchman
2019-02-06 10:24:43 -05:00
committed by GitHub
parent 4429826229
commit 45b70ae031
6 changed files with 51 additions and 24 deletions

View File

@ -88,13 +88,13 @@ func TestSplitAndTrimEmpty(t *testing.T) {
}
}
func TestNodeDelayedStop(t *testing.T) {
config := cfg.ResetTestRoot("node_delayed_node_test")
func TestNodeDelayedStart(t *testing.T) {
config := cfg.ResetTestRoot("node_delayed_start_test")
now := tmtime.Now()
// create & start node
n, err := DefaultNewNode(config, log.TestingLogger())
n.GenesisDoc().GenesisTime = now.Add(5 * time.Second)
n.GenesisDoc().GenesisTime = now.Add(2 * time.Second)
require.NoError(t, err)
n.Start()
@ -133,6 +133,7 @@ func TestNodeSetPrivValTCP(t *testing.T) {
types.NewMockPV(),
dialer,
)
privval.RemoteSignerConnDeadline(100 * time.Millisecond)(pvsc)
go func() {
err := pvsc.Start()
@ -172,20 +173,18 @@ func TestNodeSetPrivValIPC(t *testing.T) {
types.NewMockPV(),
dialer,
)
privval.RemoteSignerConnDeadline(100 * time.Millisecond)(pvsc)
done := make(chan struct{})
go func() {
defer close(done)
n, err := DefaultNewNode(config, log.TestingLogger())
err := pvsc.Start()
require.NoError(t, err)
assert.IsType(t, &privval.SocketVal{}, n.PrivValidator())
}()
err := pvsc.Start()
require.NoError(t, err)
defer pvsc.Stop()
<-done
n, err := DefaultNewNode(config, log.TestingLogger())
require.NoError(t, err)
assert.IsType(t, &privval.SocketVal{}, n.PrivValidator())
}
// testFreeAddr claims a free port so we don't block on listener being ready.