mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-05 04:55:18 +00:00
lint: errcheck (#5091)
## Description add more error checks to tests gonna do a third PR that tackles the non test cases
This commit is contained in:
@@ -63,7 +63,11 @@ func TestReactor_Receive_ChunkRequest(t *testing.T) {
|
||||
r := NewReactor(conn, nil, "")
|
||||
err := r.Start()
|
||||
require.NoError(t, err)
|
||||
defer r.Stop()
|
||||
t.Cleanup(func() {
|
||||
if err := r.Stop(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
})
|
||||
|
||||
r.Receive(ChunkChannel, peer, mustEncodeMsg(tc.request))
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
@@ -136,7 +140,11 @@ func TestReactor_Receive_SnapshotsRequest(t *testing.T) {
|
||||
r := NewReactor(conn, nil, "")
|
||||
err := r.Start()
|
||||
require.NoError(t, err)
|
||||
defer r.Stop()
|
||||
t.Cleanup(func() {
|
||||
if err := r.Stop(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
})
|
||||
|
||||
r.Receive(SnapshotChannel, peer, mustEncodeMsg(&ssproto.SnapshotsRequest{}))
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
@@ -218,12 +218,13 @@ func TestSyncer_SyncAny_abort(t *testing.T) {
|
||||
syncer, connSnapshot := setupOfferSyncer(t)
|
||||
|
||||
s := &snapshot{Height: 1, Format: 1, Chunks: 3, Hash: []byte{1, 2, 3}}
|
||||
syncer.AddSnapshot(simplePeer("id"), s)
|
||||
_, err := syncer.AddSnapshot(simplePeer("id"), s)
|
||||
require.NoError(t, err)
|
||||
connSnapshot.On("OfferSnapshotSync", abci.RequestOfferSnapshot{
|
||||
Snapshot: toABCI(s), AppHash: []byte("app_hash"),
|
||||
}).Once().Return(&abci.ResponseOfferSnapshot{Result: abci.ResponseOfferSnapshot_ABORT}, nil)
|
||||
|
||||
_, _, err := syncer.SyncAny(0)
|
||||
_, _, err = syncer.SyncAny(0)
|
||||
assert.Equal(t, errAbort, err)
|
||||
connSnapshot.AssertExpectations(t)
|
||||
}
|
||||
@@ -235,9 +236,12 @@ func TestSyncer_SyncAny_reject(t *testing.T) {
|
||||
s22 := &snapshot{Height: 2, Format: 2, Chunks: 3, Hash: []byte{1, 2, 3}}
|
||||
s12 := &snapshot{Height: 1, Format: 2, Chunks: 3, Hash: []byte{1, 2, 3}}
|
||||
s11 := &snapshot{Height: 1, Format: 1, Chunks: 3, Hash: []byte{1, 2, 3}}
|
||||
syncer.AddSnapshot(simplePeer("id"), s22)
|
||||
syncer.AddSnapshot(simplePeer("id"), s12)
|
||||
syncer.AddSnapshot(simplePeer("id"), s11)
|
||||
_, err := syncer.AddSnapshot(simplePeer("id"), s22)
|
||||
require.NoError(t, err)
|
||||
_, err = syncer.AddSnapshot(simplePeer("id"), s12)
|
||||
require.NoError(t, err)
|
||||
_, err = syncer.AddSnapshot(simplePeer("id"), s11)
|
||||
require.NoError(t, err)
|
||||
|
||||
connSnapshot.On("OfferSnapshotSync", abci.RequestOfferSnapshot{
|
||||
Snapshot: toABCI(s22), AppHash: []byte("app_hash"),
|
||||
@@ -251,7 +255,7 @@ func TestSyncer_SyncAny_reject(t *testing.T) {
|
||||
Snapshot: toABCI(s11), AppHash: []byte("app_hash"),
|
||||
}).Once().Return(&abci.ResponseOfferSnapshot{Result: abci.ResponseOfferSnapshot_REJECT}, nil)
|
||||
|
||||
_, _, err := syncer.SyncAny(0)
|
||||
_, _, err = syncer.SyncAny(0)
|
||||
assert.Equal(t, errNoSnapshots, err)
|
||||
connSnapshot.AssertExpectations(t)
|
||||
}
|
||||
@@ -263,9 +267,12 @@ func TestSyncer_SyncAny_reject_format(t *testing.T) {
|
||||
s22 := &snapshot{Height: 2, Format: 2, Chunks: 3, Hash: []byte{1, 2, 3}}
|
||||
s12 := &snapshot{Height: 1, Format: 2, Chunks: 3, Hash: []byte{1, 2, 3}}
|
||||
s11 := &snapshot{Height: 1, Format: 1, Chunks: 3, Hash: []byte{1, 2, 3}}
|
||||
syncer.AddSnapshot(simplePeer("id"), s22)
|
||||
syncer.AddSnapshot(simplePeer("id"), s12)
|
||||
syncer.AddSnapshot(simplePeer("id"), s11)
|
||||
_, err := syncer.AddSnapshot(simplePeer("id"), s22)
|
||||
require.NoError(t, err)
|
||||
_, err = syncer.AddSnapshot(simplePeer("id"), s12)
|
||||
require.NoError(t, err)
|
||||
_, err = syncer.AddSnapshot(simplePeer("id"), s11)
|
||||
require.NoError(t, err)
|
||||
|
||||
connSnapshot.On("OfferSnapshotSync", abci.RequestOfferSnapshot{
|
||||
Snapshot: toABCI(s22), AppHash: []byte("app_hash"),
|
||||
@@ -275,7 +282,7 @@ func TestSyncer_SyncAny_reject_format(t *testing.T) {
|
||||
Snapshot: toABCI(s11), AppHash: []byte("app_hash"),
|
||||
}).Once().Return(&abci.ResponseOfferSnapshot{Result: abci.ResponseOfferSnapshot_ABORT}, nil)
|
||||
|
||||
_, _, err := syncer.SyncAny(0)
|
||||
_, _, err = syncer.SyncAny(0)
|
||||
assert.Equal(t, errAbort, err)
|
||||
connSnapshot.AssertExpectations(t)
|
||||
}
|
||||
@@ -323,12 +330,13 @@ func TestSyncer_SyncAny_abciError(t *testing.T) {
|
||||
|
||||
errBoom := errors.New("boom")
|
||||
s := &snapshot{Height: 1, Format: 1, Chunks: 3, Hash: []byte{1, 2, 3}}
|
||||
syncer.AddSnapshot(simplePeer("id"), s)
|
||||
_, err := syncer.AddSnapshot(simplePeer("id"), s)
|
||||
require.NoError(t, err)
|
||||
connSnapshot.On("OfferSnapshotSync", abci.RequestOfferSnapshot{
|
||||
Snapshot: toABCI(s), AppHash: []byte("app_hash"),
|
||||
}).Once().Return(nil, errBoom)
|
||||
|
||||
_, _, err := syncer.SyncAny(0)
|
||||
_, _, err = syncer.SyncAny(0)
|
||||
assert.True(t, errors.Is(err, errBoom))
|
||||
connSnapshot.AssertExpectations(t)
|
||||
}
|
||||
@@ -403,7 +411,8 @@ func TestSyncer_applyChunks_Results(t *testing.T) {
|
||||
|
||||
body := []byte{1, 2, 3}
|
||||
chunks, err := newChunkQueue(&snapshot{Height: 1, Format: 1, Chunks: 1}, "")
|
||||
chunks.Add(&chunk{Height: 1, Format: 1, Index: 0, Chunk: body})
|
||||
require.NoError(t, err)
|
||||
_, err = chunks.Add(&chunk{Height: 1, Format: 1, Index: 0, Chunk: body})
|
||||
require.NoError(t, err)
|
||||
|
||||
connSnapshot.On("ApplySnapshotChunkSync", abci.RequestApplySnapshotChunk{
|
||||
@@ -481,7 +490,7 @@ func TestSyncer_applyChunks_RefetchChunks(t *testing.T) {
|
||||
// check the queue contents, and finally close the queue to end the goroutine.
|
||||
// We don't really care about the result of applyChunks, since it has separate test.
|
||||
go func() {
|
||||
syncer.applyChunks(chunks)
|
||||
syncer.applyChunks(chunks) //nolint:errcheck // purposefully ignore error
|
||||
}()
|
||||
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
@@ -522,12 +531,18 @@ func TestSyncer_applyChunks_RejectSenders(t *testing.T) {
|
||||
|
||||
s1 := &snapshot{Height: 1, Format: 1, Chunks: 3}
|
||||
s2 := &snapshot{Height: 2, Format: 1, Chunks: 3}
|
||||
syncer.AddSnapshot(peerA, s1)
|
||||
syncer.AddSnapshot(peerA, s2)
|
||||
syncer.AddSnapshot(peerB, s1)
|
||||
syncer.AddSnapshot(peerB, s2)
|
||||
syncer.AddSnapshot(peerC, s1)
|
||||
syncer.AddSnapshot(peerC, s2)
|
||||
_, err := syncer.AddSnapshot(peerA, s1)
|
||||
require.NoError(t, err)
|
||||
_, err = syncer.AddSnapshot(peerA, s2)
|
||||
require.NoError(t, err)
|
||||
_, err = syncer.AddSnapshot(peerB, s1)
|
||||
require.NoError(t, err)
|
||||
_, err = syncer.AddSnapshot(peerB, s2)
|
||||
require.NoError(t, err)
|
||||
_, err = syncer.AddSnapshot(peerC, s1)
|
||||
require.NoError(t, err)
|
||||
_, err = syncer.AddSnapshot(peerC, s2)
|
||||
require.NoError(t, err)
|
||||
|
||||
chunks, err := newChunkQueue(s1, "")
|
||||
require.NoError(t, err)
|
||||
@@ -566,7 +581,7 @@ func TestSyncer_applyChunks_RejectSenders(t *testing.T) {
|
||||
// However, it will block on e.g. retry result, so we spawn a goroutine that will
|
||||
// be shut down when the chunk queue closes.
|
||||
go func() {
|
||||
syncer.applyChunks(chunks)
|
||||
syncer.applyChunks(chunks) //nolint:errcheck // purposefully ignore error
|
||||
}()
|
||||
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
Reference in New Issue
Block a user