Browse Source

tests: update cleanup opertunities (#7647)

pull/7650/head
Sam Kleinman 3 years ago
committed by GitHub
parent
commit
9dd67ad99d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 8 deletions
  1. +5
    -2
      abci/client/socket_client_test.go
  2. +3
    -5
      internal/consensus/reactor_test.go
  3. +3
    -1
      internal/mempool/reactor_test.go

+ 5
- 2
abci/client/socket_client_test.go View File

@ -23,7 +23,7 @@ func TestProperSyncCalls(t *testing.T) {
defer cancel() defer cancel()
app := slowApp{} app := slowApp{}
logger := log.TestingLogger()
logger := log.NewNopLogger()
_, c := setupClientServer(ctx, t, logger, app) _, c := setupClientServer(ctx, t, logger, app)
@ -33,7 +33,10 @@ func TestProperSyncCalls(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.NoError(t, c.Flush(ctx)) assert.NoError(t, c.Flush(ctx))
assert.NotNil(t, rsp) assert.NotNil(t, rsp)
resp <- c.Error()
select {
case <-ctx.Done():
case resp <- c.Error():
}
}() }()
select { select {


+ 3
- 5
internal/consensus/reactor_test.go View File

@ -81,7 +81,7 @@ func setup(
rts.voteSetBitsChannels = rts.network.MakeChannelsNoCleanup(ctx, t, chDesc(VoteSetBitsChannel, size)) rts.voteSetBitsChannels = rts.network.MakeChannelsNoCleanup(ctx, t, chDesc(VoteSetBitsChannel, size))
ctx, cancel := context.WithCancel(ctx) ctx, cancel := context.WithCancel(ctx)
// Canceled during cleanup (see below).
t.Cleanup(cancel)
chCreator := func(nodeID types.NodeID) p2p.ChannelCreator { chCreator := func(nodeID types.NodeID) p2p.ChannelCreator {
return func(ctx context.Context, desc *p2p.ChannelDescriptor) (*p2p.Channel, error) { return func(ctx context.Context, desc *p2p.ChannelDescriptor) (*p2p.Channel, error) {
@ -142,6 +142,7 @@ func setup(
require.NoError(t, reactor.Start(ctx)) require.NoError(t, reactor.Start(ctx))
require.True(t, reactor.IsRunning()) require.True(t, reactor.IsRunning())
t.Cleanup(reactor.Wait)
i++ i++
} }
@ -151,10 +152,7 @@ func setup(
// start the in-memory network and connect all peers with each other // start the in-memory network and connect all peers with each other
rts.network.Start(ctx, t) rts.network.Start(ctx, t)
t.Cleanup(func() {
cancel()
leaktest.Check(t)
})
t.Cleanup(leaktest.Check(t))
return rts return rts
} }


+ 3
- 1
internal/mempool/reactor_test.go View File

@ -45,7 +45,7 @@ func setupReactors(ctx context.Context, t *testing.T, numNodes int, chBuf uint)
t.Cleanup(func() { os.RemoveAll(cfg.RootDir) }) t.Cleanup(func() { os.RemoveAll(cfg.RootDir) })
rts := &reactorTestSuite{ rts := &reactorTestSuite{
logger: log.TestingLogger().With("testCase", t.Name()),
logger: log.NewNopLogger().With("testCase", t.Name()),
network: p2ptest.MakeNetwork(ctx, t, p2ptest.NetworkOptions{NumNodes: numNodes}), network: p2ptest.MakeNetwork(ctx, t, p2ptest.NetworkOptions{NumNodes: numNodes}),
reactors: make(map[types.NodeID]*Reactor, numNodes), reactors: make(map[types.NodeID]*Reactor, numNodes),
mempoolChannels: make(map[types.NodeID]*p2p.Channel, numNodes), mempoolChannels: make(map[types.NodeID]*p2p.Channel, numNodes),
@ -95,8 +95,10 @@ func setupReactors(ctx context.Context, t *testing.T, numNodes int, chBuf uint)
for nodeID := range rts.reactors { for nodeID := range rts.reactors {
if rts.reactors[nodeID].IsRunning() { if rts.reactors[nodeID].IsRunning() {
require.NoError(t, rts.reactors[nodeID].Stop()) require.NoError(t, rts.reactors[nodeID].Stop())
rts.reactors[nodeID].Wait()
require.False(t, rts.reactors[nodeID].IsRunning()) require.False(t, rts.reactors[nodeID].IsRunning())
} }
} }
}) })


Loading…
Cancel
Save