consensus: test shutdown to avoid hangs (#7603)

This commit is contained in:
Sam Kleinman
2022-01-18 08:55:13 -05:00
committed by GitHub
parent 49153b753c
commit c0b56e207a
4 changed files with 12 additions and 3 deletions

View File

@@ -255,7 +255,6 @@ func TestByzantinePrevoteEquivocation(t *testing.T) {
}
msg, err := s.Next(ctx)
assert.NoError(t, err)
if err != nil {
cancel()

View File

@@ -201,6 +201,8 @@ LOOP:
i++
select {
case <-rctx.Done():
t.Fatal("context canceled before test completed")
case err := <-walPanicked:
// make sure we can make blocks after a crash
startNewStateAndWaitForBlock(ctx, t, consensusReplayConfig, cs.Height, blockDB, stateStore)

View File

@@ -2131,7 +2131,11 @@ func subscribe(
t.Errorf("Subscription for %v unexpectedly terminated: %v", q, err)
return
}
ch <- next
select {
case ch <- next:
case <-ctx.Done():
return
}
}
}()
return ch

View File

@@ -3,6 +3,7 @@ package consensus
import (
"bytes"
"context"
"errors"
"path/filepath"
"testing"
@@ -15,6 +16,7 @@ import (
"github.com/tendermint/tendermint/internal/consensus/types"
"github.com/tendermint/tendermint/internal/libs/autofile"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/libs/service"
tmtime "github.com/tendermint/tendermint/libs/time"
tmtypes "github.com/tendermint/tendermint/types"
)
@@ -185,7 +187,9 @@ func TestWALPeriodicSync(t *testing.T) {
require.NoError(t, wal.Start(ctx))
t.Cleanup(func() {
if err := wal.Stop(); err != nil {
t.Error(err)
if !errors.Is(err, service.ErrAlreadyStopped) {
t.Error(err)
}
}
wal.Wait()
})