Browse Source

linter: (1/2) enable errcheck (#5064)

## Description

partially cleanup in preparation for errcheck

i ignored a bunch of defer errors in tests but with the update to go 1.14 we can use `t.Cleanup(func() { if err := <>; err != nil {..}}` to cover those errors, I will do this in pr number two of enabling errcheck.

ref #5059
pull/5073/head
Marko 4 years ago
committed by GitHub
parent
commit
7e2cc1db5e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 289 additions and 200 deletions
  1. +3
    -3
      abci/example/example_test.go
  2. +10
    -6
      abci/example/kvstore/kvstore_test.go
  3. +14
    -6
      blockchain/v0/reactor_test.go
  4. +1
    -1
      config/toml_test.go
  5. +1
    -1
      consensus/replay.go
  6. +1
    -1
      consensus/replay_file.go
  7. +1
    -1
      consensus/replay_test.go
  8. +5
    -1
      crypto/internal/benchmarking/bench.go
  9. +9
    -4
      crypto/tmhash/hash_test.go
  10. +9
    -3
      libs/events/event_cache_test.go
  11. +53
    -30
      libs/events/events_test.go
  12. +3
    -3
      libs/log/tm_logger.go
  13. +1
    -1
      libs/log/tmfmt_logger.go
  14. +48
    -31
      libs/pubsub/pubsub_test.go
  15. +8
    -5
      libs/service/service_test.go
  16. +7
    -6
      node/node_test.go
  17. +2
    -2
      p2p/conn/connection.go
  18. +27
    -27
      p2p/conn/connection_test.go
  19. +1
    -1
      p2p/fuzz.go
  20. +1
    -1
      p2p/peer.go
  21. +1
    -1
      p2p/pex/file.go
  22. +38
    -30
      p2p/pex/pex_reactor_test.go
  23. +5
    -5
      p2p/upnp/upnp.go
  24. +2
    -2
      rpc/client/mock/abci.go
  25. +2
    -2
      rpc/jsonrpc/client/http_json_client.go
  26. +1
    -1
      rpc/jsonrpc/client/http_uri_client.go
  27. +7
    -6
      rpc/jsonrpc/client/ws_client_test.go
  28. +3
    -2
      rpc/jsonrpc/server/http_server_test.go
  29. +4
    -1
      rpc/jsonrpc/test/main.go
  30. +1
    -1
      scripts/wal2json/main.go
  31. +7
    -6
      state/execution_test.go
  32. +1
    -1
      state/txindex/kv/kv_test.go
  33. +5
    -4
      state/validation_test.go
  34. +6
    -3
      store/store_test.go
  35. +1
    -1
      tools/tm-signer-harness/internal/test_harness_test.go

+ 3
- 3
abci/example/example_test.go View File

@ -56,7 +56,7 @@ func testStream(t *testing.T, app types.Application) {
if err := server.Start(); err != nil {
require.NoError(t, err, "Error starting socket server")
}
defer server.Stop()
defer server.Stop() //nolint:errcheck // ignore for tests
// Connect to the socket
client := abcicli.NewSocketClient(socket, false)
@ -64,7 +64,7 @@ func testStream(t *testing.T, app types.Application) {
if err := client.Start(); err != nil {
t.Fatalf("Error starting socket client: %v", err.Error())
}
defer client.Stop()
defer client.Stop() //nolint:errcheck // ignore for tests
done := make(chan struct{})
counter := 0
@ -132,7 +132,7 @@ func testGRPCSync(t *testing.T, app types.ABCIApplicationServer) {
if err := server.Start(); err != nil {
t.Fatalf("Error starting GRPC server: %v", err.Error())
}
defer server.Stop()
defer server.Stop() //nolint:errcheck // ignore for tests
// Connect to the socket
conn, err := grpc.Dial(socket, grpc.WithInsecure(), grpc.WithContextDialer(dialerFunc))


+ 10
- 6
abci/example/kvstore/kvstore_test.go View File

@ -241,7 +241,9 @@ func makeSocketClientServer(app types.Application, name string) (abcicli.Client,
client := abcicli.NewSocketClient(socket, false)
client.SetLogger(logger.With("module", "abci-client"))
if err := client.Start(); err != nil {
server.Stop()
if err = server.Stop(); err != nil {
return nil, nil, err
}
return nil, nil, err
}
@ -263,7 +265,9 @@ func makeGRPCClientServer(app types.Application, name string) (abcicli.Client, s
client := abcicli.NewGRPCClient(socket, true)
client.SetLogger(logger.With("module", "abci-client"))
if err := client.Start(); err != nil {
server.Stop()
if err := server.Stop(); err != nil {
return nil, nil, err
}
return nil, nil, err
}
return client, server, nil
@ -274,8 +278,8 @@ func TestClientServer(t *testing.T) {
kvstore := NewApplication()
client, server, err := makeSocketClientServer(kvstore, "kvstore-socket")
require.NoError(t, err)
defer server.Stop()
defer client.Stop()
defer server.Stop() //nolint:errcheck // ignore for tests
defer client.Stop() //nolint:errcheck // ignore for tests
runClientTests(t, client)
@ -283,8 +287,8 @@ func TestClientServer(t *testing.T) {
kvstore = NewApplication()
gclient, gserver, err := makeGRPCClientServer(kvstore, "kvstore-grpc")
require.NoError(t, err)
defer gserver.Stop()
defer gclient.Stop()
defer gserver.Stop() //nolint:errcheck // ignore for tests
defer gclient.Stop() //nolint:errcheck // ignore for tests
runClientTests(t, gclient)
}


+ 14
- 6
blockchain/v0/reactor_test.go View File

@ -8,6 +8,7 @@ import (
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
dbm "github.com/tendermint/tm-db"
@ -146,8 +147,10 @@ func TestNoBlockResponse(t *testing.T) {
defer func() {
for _, r := range reactorPairs {
r.reactor.Stop()
r.app.Stop()
err := r.reactor.Stop()
require.NoError(t, err)
err = r.app.Stop()
require.NoError(t, err)
}
}()
@ -195,8 +198,10 @@ func TestBadBlockStopsPeer(t *testing.T) {
otherChain := newBlockchainReactor(log.TestingLogger(), genDoc, privVals, maxBlockHeight)
defer func() {
otherChain.reactor.Stop()
otherChain.app.Stop()
err := otherChain.reactor.Stop()
require.Error(t, err)
err = otherChain.app.Stop()
require.NoError(t, err)
}()
reactorPairs := make([]BlockchainReactorPair, 4)
@ -214,8 +219,11 @@ func TestBadBlockStopsPeer(t *testing.T) {
defer func() {
for _, r := range reactorPairs {
r.reactor.Stop()
r.app.Stop()
err := r.reactor.Stop()
require.NoError(t, err)
err = r.app.Stop()
require.NoError(t, err)
}
}()


+ 1
- 1
config/toml_test.go View File

@ -25,7 +25,7 @@ func TestEnsureRoot(t *testing.T) {
// setup temp dir for test
tmpDir, err := ioutil.TempDir("", "config-test")
require.Nil(err)
defer os.RemoveAll(tmpDir) // nolint: errcheck
defer os.RemoveAll(tmpDir)
// create root dir
EnsureRoot(tmpDir)


+ 1
- 1
consensus/replay.go View File

@ -128,7 +128,7 @@ func (cs *State) catchupReplay(csHeight int64) error {
if !found {
return fmt.Errorf("cannot replay height %d. WAL does not contain #ENDHEIGHT for %d", csHeight, csHeight-1)
}
defer gr.Close() // nolint: errcheck
defer gr.Close()
cs.Logger.Info("Catchup by replaying consensus messages", "height", csHeight)


+ 1
- 1
consensus/replay_file.go View File

@ -66,7 +66,7 @@ func (cs *State) ReplayFile(file string, console bool) error {
}
pb := newPlayback(file, fp, cs, cs.state.Copy())
defer pb.fp.Close() // nolint: errcheck
defer pb.fp.Close()
var nextN int // apply N msgs in a row
var msg *TimedWALMessage


+ 1
- 1
consensus/replay_test.go View File

@ -1002,7 +1002,7 @@ func makeBlockchainFromWAL(wal WAL) ([]*types.Block, []*types.Commit, error) {
if !found {
return nil, nil, fmt.Errorf("wal does not contain height %d", height)
}
defer gr.Close() // nolint: errcheck
defer gr.Close()
// log.Notice("Build a blockchain by reading from the WAL")


+ 5
- 1
crypto/internal/benchmarking/bench.go View File

@ -37,7 +37,11 @@ func BenchmarkSigning(b *testing.B, priv crypto.PrivKey) {
message := []byte("Hello, world!")
b.ResetTimer()
for i := 0; i < b.N; i++ {
priv.Sign(message)
_, err := priv.Sign(message)
if err != nil {
b.FailNow()
}
}
}


+ 9
- 4
crypto/tmhash/hash_test.go View File

@ -5,6 +5,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/tmhash"
)
@ -12,13 +13,15 @@ import (
func TestHash(t *testing.T) {
testVector := []byte("abc")
hasher := tmhash.New()
hasher.Write(testVector)
_, err := hasher.Write(testVector)
require.NoError(t, err)
bz := hasher.Sum(nil)
bz2 := tmhash.Sum(testVector)
hasher = sha256.New()
hasher.Write(testVector)
_, err = hasher.Write(testVector)
require.NoError(t, err)
bz3 := hasher.Sum(nil)
assert.Equal(t, bz, bz2)
@ -28,13 +31,15 @@ func TestHash(t *testing.T) {
func TestHashTruncated(t *testing.T) {
testVector := []byte("abc")
hasher := tmhash.NewTruncated()
hasher.Write(testVector)
_, err := hasher.Write(testVector)
require.NoError(t, err)
bz := hasher.Sum(nil)
bz2 := tmhash.SumTruncated(testVector)
hasher = sha256.New()
hasher.Write(testVector)
_, err = hasher.Write(testVector)
require.NoError(t, err)
bz3 := hasher.Sum(nil)
bz3 = bz3[:tmhash.TruncatedSize]


+ 9
- 3
libs/events/event_cache_test.go View File

@ -9,23 +9,29 @@ import (
func TestEventCache_Flush(t *testing.T) {
evsw := NewEventSwitch()
evsw.Start()
evsw.AddListenerForEvent("nothingness", "", func(data EventData) {
err := evsw.Start()
require.NoError(t, err)
err = evsw.AddListenerForEvent("nothingness", "", func(data EventData) {
// Check we are not initialising an empty buffer full of zeroed eventInfos in the EventCache
require.FailNow(t, "We should never receive a message on this switch since none are fired")
})
require.NoError(t, err)
evc := NewEventCache(evsw)
evc.Flush()
// Check after reset
evc.Flush()
fail := true
pass := false
evsw.AddListenerForEvent("somethingness", "something", func(data EventData) {
err = evsw.AddListenerForEvent("somethingness", "something", func(data EventData) {
if fail {
require.FailNow(t, "Shouldn't see a message until flushed")
}
pass = true
})
require.NoError(t, err)
evc.FireEvent("something", struct{ int }{1})
evc.FireEvent("something", struct{ int }{2})
evc.FireEvent("something", struct{ int }{3})


+ 53
- 30
libs/events/events_test.go View File

@ -17,15 +17,16 @@ func TestAddListenerForEventFireOnce(t *testing.T) {
evsw := NewEventSwitch()
err := evsw.Start()
require.NoError(t, err)
defer evsw.Stop()
defer evsw.Stop() //nolint:errcheck // ignore for tests
messages := make(chan EventData)
evsw.AddListenerForEvent("listener", "event",
err = evsw.AddListenerForEvent("listener", "event",
func(data EventData) {
// test there's no deadlock if we remove the listener inside a callback
evsw.RemoveListener("listener")
messages <- data
})
require.NoError(t, err)
go evsw.FireEvent("event", "data")
received := <-messages
if received != "data" {
@ -39,16 +40,17 @@ func TestAddListenerForEventFireMany(t *testing.T) {
evsw := NewEventSwitch()
err := evsw.Start()
require.NoError(t, err)
defer evsw.Stop()
defer evsw.Stop() //nolint:errcheck // ignore for tests
doneSum := make(chan uint64)
doneSending := make(chan uint64)
numbers := make(chan uint64, 4)
// subscribe one listener for one event
evsw.AddListenerForEvent("listener", "event",
err = evsw.AddListenerForEvent("listener", "event",
func(data EventData) {
numbers <- data.(uint64)
})
require.NoError(t, err)
// collect received events
go sumReceivedNumbers(numbers, doneSum)
// go fire events
@ -68,7 +70,7 @@ func TestAddListenerForDifferentEvents(t *testing.T) {
evsw := NewEventSwitch()
err := evsw.Start()
require.NoError(t, err)
defer evsw.Stop()
defer evsw.Stop() //nolint:errcheck // ignore for tests
doneSum := make(chan uint64)
doneSending1 := make(chan uint64)
@ -76,18 +78,21 @@ func TestAddListenerForDifferentEvents(t *testing.T) {
doneSending3 := make(chan uint64)
numbers := make(chan uint64, 4)
// subscribe one listener to three events
evsw.AddListenerForEvent("listener", "event1",
err = evsw.AddListenerForEvent("listener", "event1",
func(data EventData) {
numbers <- data.(uint64)
})
evsw.AddListenerForEvent("listener", "event2",
require.NoError(t, err)
err = evsw.AddListenerForEvent("listener", "event2",
func(data EventData) {
numbers <- data.(uint64)
})
evsw.AddListenerForEvent("listener", "event3",
require.NoError(t, err)
err = evsw.AddListenerForEvent("listener", "event3",
func(data EventData) {
numbers <- data.(uint64)
})
require.NoError(t, err)
// collect received events
go sumReceivedNumbers(numbers, doneSum)
// go fire events
@ -113,7 +118,7 @@ func TestAddDifferentListenerForDifferentEvents(t *testing.T) {
evsw := NewEventSwitch()
err := evsw.Start()
require.NoError(t, err)
defer evsw.Stop()
defer evsw.Stop() //nolint:errcheck // ignore for tests
doneSum1 := make(chan uint64)
doneSum2 := make(chan uint64)
@ -123,26 +128,31 @@ func TestAddDifferentListenerForDifferentEvents(t *testing.T) {
numbers1 := make(chan uint64, 4)
numbers2 := make(chan uint64, 4)
// subscribe two listener to three events
evsw.AddListenerForEvent("listener1", "event1",
err = evsw.AddListenerForEvent("listener1", "event1",
func(data EventData) {
numbers1 <- data.(uint64)
})
evsw.AddListenerForEvent("listener1", "event2",
require.NoError(t, err)
err = evsw.AddListenerForEvent("listener1", "event2",
func(data EventData) {
numbers1 <- data.(uint64)
})
evsw.AddListenerForEvent("listener1", "event3",
require.NoError(t, err)
err = evsw.AddListenerForEvent("listener1", "event3",
func(data EventData) {
numbers1 <- data.(uint64)
})
evsw.AddListenerForEvent("listener2", "event2",
require.NoError(t, err)
err = evsw.AddListenerForEvent("listener2", "event2",
func(data EventData) {
numbers2 <- data.(uint64)
})
evsw.AddListenerForEvent("listener2", "event3",
require.NoError(t, err)
err = evsw.AddListenerForEvent("listener2", "event3",
func(data EventData) {
numbers2 <- data.(uint64)
})
require.NoError(t, err)
// collect received events for listener1
go sumReceivedNumbers(numbers1, doneSum1)
// collect received events for listener2
@ -175,7 +185,7 @@ func TestAddAndRemoveListenerConcurrency(t *testing.T) {
evsw := NewEventSwitch()
err := evsw.Start()
require.NoError(t, err)
defer evsw.Stop()
defer evsw.Stop() //nolint:errcheck // ignore for tests
done1 := make(chan struct{})
done2 := make(chan struct{})
@ -193,11 +203,12 @@ func TestAddAndRemoveListenerConcurrency(t *testing.T) {
go func() {
for i := 0; i < roundCount; i++ {
index := i
evsw.AddListenerForEvent("listener", fmt.Sprintf("event%d", index),
err = evsw.AddListenerForEvent("listener", fmt.Sprintf("event%d", index),
func(data EventData) {
t.Errorf("should not run callback for %d.\n", index)
stopInputEvent = true
})
require.NoError(t, err)
}
close(done2)
}()
@ -219,7 +230,7 @@ func TestAddAndRemoveListener(t *testing.T) {
evsw := NewEventSwitch()
err := evsw.Start()
require.NoError(t, err)
defer evsw.Stop()
defer evsw.Stop() //nolint:errcheck // ignore for tests
doneSum1 := make(chan uint64)
doneSum2 := make(chan uint64)
@ -228,14 +239,16 @@ func TestAddAndRemoveListener(t *testing.T) {
numbers1 := make(chan uint64, 4)
numbers2 := make(chan uint64, 4)
// subscribe two listener to three events
evsw.AddListenerForEvent("listener", "event1",
err = evsw.AddListenerForEvent("listener", "event1",
func(data EventData) {
numbers1 <- data.(uint64)
})
evsw.AddListenerForEvent("listener", "event2",
require.NoError(t, err)
err = evsw.AddListenerForEvent("listener", "event2",
func(data EventData) {
numbers2 <- data.(uint64)
})
require.NoError(t, err)
// collect received events for event1
go sumReceivedNumbers(numbers1, doneSum1)
// collect received events for event2
@ -264,19 +277,23 @@ func TestRemoveListener(t *testing.T) {
evsw := NewEventSwitch()
err := evsw.Start()
require.NoError(t, err)
defer evsw.Stop()
defer evsw.Stop() //nolint:errcheck // ignore for tests
count := 10
sum1, sum2 := 0, 0
// add some listeners and make sure they work
evsw.AddListenerForEvent("listener", "event1",
err = evsw.AddListenerForEvent("listener", "event1",
func(data EventData) {
sum1++
})
evsw.AddListenerForEvent("listener", "event2",
require.NoError(t, err)
err = evsw.AddListenerForEvent("listener", "event2",
func(data EventData) {
sum2++
})
require.NoError(t, err)
for i := 0; i < count; i++ {
evsw.FireEvent("event1", true)
evsw.FireEvent("event2", true)
@ -317,7 +334,7 @@ func TestRemoveListenersAsync(t *testing.T) {
evsw := NewEventSwitch()
err := evsw.Start()
require.NoError(t, err)
defer evsw.Stop()
defer evsw.Stop() //nolint:errcheck // ignore for tests
doneSum1 := make(chan uint64)
doneSum2 := make(chan uint64)
@ -327,30 +344,36 @@ func TestRemoveListenersAsync(t *testing.T) {
numbers1 := make(chan uint64, 4)
numbers2 := make(chan uint64, 4)
// subscribe two listener to three events
evsw.AddListenerForEvent("listener1", "event1",
err = evsw.AddListenerForEvent("listener1", "event1",
func(data EventData) {
numbers1 <- data.(uint64)
})
evsw.AddListenerForEvent("listener1", "event2",
require.NoError(t, err)
err = evsw.AddListenerForEvent("listener1", "event2",
func(data EventData) {
numbers1 <- data.(uint64)
})
evsw.AddListenerForEvent("listener1", "event3",
require.NoError(t, err)
err = evsw.AddListenerForEvent("listener1", "event3",
func(data EventData) {
numbers1 <- data.(uint64)
})
evsw.AddListenerForEvent("listener2", "event1",
require.NoError(t, err)
err = evsw.AddListenerForEvent("listener2", "event1",
func(data EventData) {
numbers2 <- data.(uint64)
})
evsw.AddListenerForEvent("listener2", "event2",
require.NoError(t, err)
err = evsw.AddListenerForEvent("listener2", "event2",
func(data EventData) {
numbers2 <- data.(uint64)
})
evsw.AddListenerForEvent("listener2", "event3",
require.NoError(t, err)
err = evsw.AddListenerForEvent("listener2", "event3",
func(data EventData) {
numbers2 <- data.(uint64)
})
require.NoError(t, err)
// collect received events for event1
go sumReceivedNumbers(numbers1, doneSum1)
// collect received events for event2
@ -361,7 +384,7 @@ func TestRemoveListenersAsync(t *testing.T) {
for k := uint16(0); k < 400; k++ {
listenerNumber := r1.Intn(100) + 3
eventNumber := r1.Intn(3) + 1
go evsw.AddListenerForEvent(fmt.Sprintf("listener%v", listenerNumber),
go evsw.AddListenerForEvent(fmt.Sprintf("listener%v", listenerNumber), //nolint:errcheck // ignore for tests
fmt.Sprintf("event%v", eventNumber),
func(_ EventData) {})
}


+ 3
- 3
libs/log/tm_logger.go View File

@ -54,7 +54,7 @@ func (l *tmLogger) Info(msg string, keyvals ...interface{}) {
lWithLevel := kitlevel.Info(l.srcLogger)
if err := kitlog.With(lWithLevel, msgKey, msg).Log(keyvals...); err != nil {
errLogger := kitlevel.Error(l.srcLogger)
kitlog.With(errLogger, msgKey, msg).Log("err", err)
kitlog.With(errLogger, msgKey, msg).Log("err", err) //nolint:errcheck // no need to check error again
}
}
@ -63,7 +63,7 @@ func (l *tmLogger) Debug(msg string, keyvals ...interface{}) {
lWithLevel := kitlevel.Debug(l.srcLogger)
if err := kitlog.With(lWithLevel, msgKey, msg).Log(keyvals...); err != nil {
errLogger := kitlevel.Error(l.srcLogger)
kitlog.With(errLogger, msgKey, msg).Log("err", err)
kitlog.With(errLogger, msgKey, msg).Log("err", err) //nolint:errcheck // no need to check error again
}
}
@ -72,7 +72,7 @@ func (l *tmLogger) Error(msg string, keyvals ...interface{}) {
lWithLevel := kitlevel.Error(l.srcLogger)
lWithMsg := kitlog.With(lWithLevel, msgKey, msg)
if err := lWithMsg.Log(keyvals...); err != nil {
lWithMsg.Log("err", err)
lWithMsg.Log("err", err) //nolint:errcheck // no need to check error again
}
}


+ 1
- 1
libs/log/tmfmt_logger.go View File

@ -107,7 +107,7 @@ KeyvalueLoop:
err := enc.EncodeKeyval(keyvals[i], keyvals[i+1])
if err == logfmt.ErrUnsupportedValueType {
enc.EncodeKeyval(keyvals[i], fmt.Sprintf("%+v", keyvals[i+1]))
enc.EncodeKeyval(keyvals[i], fmt.Sprintf("%+v", keyvals[i+1])) //nolint:errcheck // no need to check error again
} else if err != nil {
return err
}


+ 48
- 31
libs/pubsub/pubsub_test.go View File

@ -23,8 +23,9 @@ const (
func TestSubscribe(t *testing.T) {
s := pubsub.NewServer()
s.SetLogger(log.TestingLogger())
s.Start()
defer s.Stop()
err := s.Start()
require.NoError(t, err)
defer s.Stop() //nolint:errcheck // ignore for tests
ctx := context.Background()
subscription, err := s.Subscribe(ctx, clientID, query.Empty{})
@ -63,15 +64,18 @@ func TestSubscribe(t *testing.T) {
func TestSubscribeWithCapacity(t *testing.T) {
s := pubsub.NewServer()
s.SetLogger(log.TestingLogger())
s.Start()
defer s.Stop()
err := s.Start()
require.NoError(t, err)
defer s.Stop() //nolint:errcheck // ignore for tests
ctx := context.Background()
assert.Panics(t, func() {
s.Subscribe(ctx, clientID, query.Empty{}, -1)
_, err = s.Subscribe(ctx, clientID, query.Empty{}, -1)
require.NoError(t, err)
})
assert.Panics(t, func() {
s.Subscribe(ctx, clientID, query.Empty{}, 0)
_, err = s.Subscribe(ctx, clientID, query.Empty{}, 0)
require.NoError(t, err)
})
subscription, err := s.Subscribe(ctx, clientID, query.Empty{}, 1)
require.NoError(t, err)
@ -83,8 +87,9 @@ func TestSubscribeWithCapacity(t *testing.T) {
func TestSubscribeUnbuffered(t *testing.T) {
s := pubsub.NewServer()
s.SetLogger(log.TestingLogger())
s.Start()
defer s.Stop()
err := s.Start()
require.NoError(t, err)
defer s.Stop() //nolint:errcheck // ignore for tests
ctx := context.Background()
subscription, err := s.SubscribeUnbuffered(ctx, clientID, query.Empty{})
@ -113,8 +118,9 @@ func TestSubscribeUnbuffered(t *testing.T) {
func TestSlowClientIsRemovedWithErrOutOfCapacity(t *testing.T) {
s := pubsub.NewServer()
s.SetLogger(log.TestingLogger())
s.Start()
defer s.Stop()
err := s.Start()
require.NoError(t, err)
defer s.Stop() //nolint:errcheck // ignore for tests
ctx := context.Background()
subscription, err := s.Subscribe(ctx, clientID, query.Empty{})
@ -130,8 +136,9 @@ func TestSlowClientIsRemovedWithErrOutOfCapacity(t *testing.T) {
func TestDifferentClients(t *testing.T) {
s := pubsub.NewServer()
s.SetLogger(log.TestingLogger())
s.Start()
defer s.Stop()
err := s.Start()
require.NoError(t, err)
defer s.Stop() //nolint:errcheck // ignore for tests
ctx := context.Background()
subscription1, err := s.Subscribe(ctx, "client-1", query.MustParse("tm.events.type='NewBlock'"))
@ -171,7 +178,7 @@ func TestSubscribeDuplicateKeys(t *testing.T) {
s := pubsub.NewServer()
s.SetLogger(log.TestingLogger())
require.NoError(t, s.Start())
defer s.Stop()
defer s.Stop() //nolint:errcheck // ignore for tests
testCases := []struct {
query string
@ -220,8 +227,9 @@ func TestSubscribeDuplicateKeys(t *testing.T) {
func TestClientSubscribesTwice(t *testing.T) {
s := pubsub.NewServer()
s.SetLogger(log.TestingLogger())
s.Start()
defer s.Stop()
err := s.Start()
require.NoError(t, err)
defer s.Stop() //nolint:errcheck // ignore for tests
ctx := context.Background()
q := query.MustParse("tm.events.type='NewBlock'")
@ -244,8 +252,9 @@ func TestClientSubscribesTwice(t *testing.T) {
func TestUnsubscribe(t *testing.T) {
s := pubsub.NewServer()
s.SetLogger(log.TestingLogger())
s.Start()
defer s.Stop()
err := s.Start()
require.NoError(t, err)
defer s.Stop() //nolint:errcheck // ignore for tests
ctx := context.Background()
subscription, err := s.Subscribe(ctx, clientID, query.MustParse("tm.events.type='NewBlock'"))
@ -263,11 +272,12 @@ func TestUnsubscribe(t *testing.T) {
func TestClientUnsubscribesTwice(t *testing.T) {
s := pubsub.NewServer()
s.SetLogger(log.TestingLogger())
s.Start()
defer s.Stop()
err := s.Start()
require.NoError(t, err)
defer s.Stop() //nolint:errcheck // ignore for tests
ctx := context.Background()
_, err := s.Subscribe(ctx, clientID, query.MustParse("tm.events.type='NewBlock'"))
_, err = s.Subscribe(ctx, clientID, query.MustParse("tm.events.type='NewBlock'"))
require.NoError(t, err)
err = s.Unsubscribe(ctx, clientID, query.MustParse("tm.events.type='NewBlock'"))
require.NoError(t, err)
@ -281,11 +291,12 @@ func TestClientUnsubscribesTwice(t *testing.T) {
func TestResubscribe(t *testing.T) {
s := pubsub.NewServer()
s.SetLogger(log.TestingLogger())
s.Start()
defer s.Stop()
err := s.Start()
require.NoError(t, err)
defer s.Stop() //nolint:errcheck // ignore for tests
ctx := context.Background()
_, err := s.Subscribe(ctx, clientID, query.Empty{})
_, err = s.Subscribe(ctx, clientID, query.Empty{})
require.NoError(t, err)
err = s.Unsubscribe(ctx, clientID, query.Empty{})
require.NoError(t, err)
@ -300,8 +311,9 @@ func TestResubscribe(t *testing.T) {
func TestUnsubscribeAll(t *testing.T) {
s := pubsub.NewServer()
s.SetLogger(log.TestingLogger())
s.Start()
defer s.Stop()
err := s.Start()
require.NoError(t, err)
defer s.Stop() //nolint:errcheck // ignore for tests
ctx := context.Background()
subscription1, err := s.Subscribe(ctx, clientID, query.MustParse("tm.events.type='NewBlock'"))
@ -351,8 +363,9 @@ func Benchmark1000ClientsOneQuery(b *testing.B) { benchmarkNClientsOneQuery(1000
func benchmarkNClients(n int, b *testing.B) {
s := pubsub.NewServer()
s.Start()
defer s.Stop()
err := s.Start()
require.NoError(b, err)
defer s.Stop() //nolint:errcheck // ignore for tests
ctx := context.Background()
for i := 0; i < n; i++ {
@ -379,18 +392,20 @@ func benchmarkNClients(n int, b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
s.PublishWithEvents(
err = s.PublishWithEvents(
ctx,
"Gamora",
map[string][]string{"abci.Account.Owner": {"Ivan"}, "abci.Invoices.Number": {string(i)}},
)
require.NoError(b, err)
}
}
func benchmarkNClientsOneQuery(n int, b *testing.B) {
s := pubsub.NewServer()
s.Start()
defer s.Stop()
err := s.Start()
require.NoError(b, err)
defer s.Stop() //nolint:errcheck // ignore for tests
ctx := context.Background()
q := query.MustParse("abci.Account.Owner = 'Ivan' AND abci.Invoices.Number = 1")
@ -414,7 +429,9 @@ func benchmarkNClientsOneQuery(n int, b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
s.PublishWithEvents(ctx, "Gamora", map[string][]string{"abci.Account.Owner": {"Ivan"}, "abci.Invoices.Number": {"1"}})
err = s.PublishWithEvents(ctx, "Gamora", map[string][]string{"abci.Account.Owner": {"Ivan"},
"abci.Invoices.Number": {"1"}})
require.NoError(b, err)
}
}


+ 8
- 5
libs/service/service_test.go View File

@ -18,7 +18,8 @@ func (testService) OnReset() error {
func TestBaseServiceWait(t *testing.T) {
ts := &testService{}
ts.BaseService = *NewBaseService(nil, "TestService", ts)
ts.Start()
err := ts.Start()
require.NoError(t, err)
waitFinished := make(chan struct{})
go func() {
@ -26,7 +27,7 @@ func TestBaseServiceWait(t *testing.T) {
waitFinished <- struct{}{}
}()
go ts.Stop()
go ts.Stop() //nolint:errcheck // ignore for tests
select {
case <-waitFinished:
@ -39,12 +40,14 @@ func TestBaseServiceWait(t *testing.T) {
func TestBaseServiceReset(t *testing.T) {
ts := &testService{}
ts.BaseService = *NewBaseService(nil, "TestService", ts)
ts.Start()
err := ts.Start()
require.NoError(t, err)
err := ts.Reset()
err = ts.Reset()
require.Error(t, err, "expected cant reset service error")
ts.Stop()
err = ts.Stop()
require.NoError(t, err)
err = ts.Reset()
require.NoError(t, err)


+ 7
- 6
node/node_test.go View File

@ -56,7 +56,8 @@ func TestNodeStartStop(t *testing.T) {
// stop the node
go func() {
n.Stop()
err = n.Stop()
require.NoError(t, err)
}()
select {
@ -104,7 +105,7 @@ func TestNodeDelayedStart(t *testing.T) {
err = n.Start()
require.NoError(t, err)
defer n.Stop()
defer n.Stop() //nolint:errcheck // ignore for tests
startTime := tmtime.Now()
assert.Equal(t, true, startTime.After(n.GenesisDoc().GenesisTime))
@ -155,7 +156,7 @@ func TestNodeSetPrivValTCP(t *testing.T) {
panic(err)
}
}()
defer signerServer.Stop()
defer signerServer.Stop() //nolint:errcheck // ignore for tests
n, err := DefaultNewNode(config, log.TestingLogger())
require.NoError(t, err)
@ -199,7 +200,7 @@ func TestNodeSetPrivValIPC(t *testing.T) {
err := pvsc.Start()
require.NoError(t, err)
}()
defer pvsc.Stop()
defer pvsc.Stop() //nolint:errcheck // ignore for tests
n, err := DefaultNewNode(config, log.TestingLogger())
require.NoError(t, err)
@ -224,7 +225,7 @@ func TestCreateProposalBlock(t *testing.T) {
proxyApp := proxy.NewAppConns(cc)
err := proxyApp.Start()
require.Nil(t, err)
defer proxyApp.Stop()
defer proxyApp.Stop() //nolint:errcheck // ignore for tests
logger := log.TestingLogger()
@ -315,7 +316,7 @@ func TestNodeNewNodeCustomReactors(t *testing.T) {
err = n.Start()
require.NoError(t, err)
defer n.Stop()
defer n.Stop() //nolint:errcheck // ignore for tests
assert.True(t, cr.IsRunning())
assert.Equal(t, cr, n.Switch().Reactor("FOO"))


+ 2
- 2
p2p/conn/connection.go View File

@ -291,7 +291,7 @@ func (c *MConnection) FlushStop() {
// Now we can close the connection
}
c.conn.Close() // nolint: errcheck
c.conn.Close()
// We can't close pong safely here because
// recvRoutine may write to it after we've stopped.
@ -307,7 +307,7 @@ func (c *MConnection) OnStop() {
return
}
c.conn.Close() // nolint: errcheck
c.conn.Close()
// We can't close pong safely here because
// recvRoutine may write to it after we've stopped.


+ 27
- 27
p2p/conn/connection_test.go View File

@ -43,13 +43,13 @@ func createMConnectionWithCallbacks(
func TestMConnectionSendFlushStop(t *testing.T) {
server, client := NetPipe()
defer server.Close() // nolint: errcheck
defer client.Close() // nolint: errcheck
defer server.Close()
defer client.Close()
clientConn := createTestMConnection(client)
err := clientConn.Start()
require.Nil(t, err)
defer clientConn.Stop()
defer clientConn.Stop() // nolint:errcheck // ignore for tests
msg := []byte("abc")
assert.True(t, clientConn.Send(0x01, msg))
@ -81,13 +81,13 @@ func TestMConnectionSendFlushStop(t *testing.T) {
func TestMConnectionSend(t *testing.T) {
server, client := NetPipe()
defer server.Close() // nolint: errcheck
defer client.Close() // nolint: errcheck
defer server.Close()
defer client.Close()
mconn := createTestMConnection(client)
err := mconn.Start()
require.Nil(t, err)
defer mconn.Stop()
defer mconn.Stop() // nolint:errcheck // ignore for tests
msg := []byte("Ant-Man")
assert.True(t, mconn.Send(0x01, msg))
@ -112,8 +112,8 @@ func TestMConnectionSend(t *testing.T) {
func TestMConnectionReceive(t *testing.T) {
server, client := NetPipe()
defer server.Close() // nolint: errcheck
defer client.Close() // nolint: errcheck
defer server.Close()
defer client.Close()
receivedCh := make(chan []byte)
errorsCh := make(chan interface{})
@ -126,12 +126,12 @@ func TestMConnectionReceive(t *testing.T) {
mconn1 := createMConnectionWithCallbacks(client, onReceive, onError)
err := mconn1.Start()
require.Nil(t, err)
defer mconn1.Stop()
defer mconn1.Stop() // nolint:errcheck // ignore for tests
mconn2 := createTestMConnection(server)
err = mconn2.Start()
require.Nil(t, err)
defer mconn2.Stop()
defer mconn2.Stop() // nolint:errcheck // ignore for tests
msg := []byte("Cyclops")
assert.True(t, mconn2.Send(0x01, msg))
@ -148,13 +148,13 @@ func TestMConnectionReceive(t *testing.T) {
func TestMConnectionStatus(t *testing.T) {
server, client := NetPipe()
defer server.Close() // nolint: errcheck
defer client.Close() // nolint: errcheck
defer server.Close()
defer client.Close()
mconn := createTestMConnection(client)
err := mconn.Start()
require.Nil(t, err)
defer mconn.Stop()
defer mconn.Stop() // nolint:errcheck // ignore for tests
status := mconn.Status()
assert.NotNil(t, status)
@ -177,7 +177,7 @@ func TestMConnectionPongTimeoutResultsInError(t *testing.T) {
mconn := createMConnectionWithCallbacks(client, onReceive, onError)
err := mconn.Start()
require.Nil(t, err)
defer mconn.Stop()
defer mconn.Stop() // nolint:errcheck // ignore for tests
serverGotPing := make(chan struct{})
go func() {
@ -216,7 +216,7 @@ func TestMConnectionMultiplePongsInTheBeginning(t *testing.T) {
mconn := createMConnectionWithCallbacks(client, onReceive, onError)
err := mconn.Start()
require.Nil(t, err)
defer mconn.Stop()
defer mconn.Stop() // nolint:errcheck // ignore for tests
// sending 3 pongs in a row (abuse)
protoWriter := protoio.NewDelimitedWriter(server)
@ -271,7 +271,7 @@ func TestMConnectionMultiplePings(t *testing.T) {
mconn := createMConnectionWithCallbacks(client, onReceive, onError)
err := mconn.Start()
require.Nil(t, err)
defer mconn.Stop()
defer mconn.Stop() // nolint:errcheck // ignore for tests
// sending 3 pings in a row (abuse)
// see https://github.com/tendermint/tendermint/issues/1190
@ -320,7 +320,7 @@ func TestMConnectionPingPongs(t *testing.T) {
mconn := createMConnectionWithCallbacks(client, onReceive, onError)
err := mconn.Start()
require.Nil(t, err)
defer mconn.Stop()
defer mconn.Stop() // nolint:errcheck // ignore for tests
serverGotPing := make(chan struct{})
go func() {
@ -364,8 +364,8 @@ func TestMConnectionPingPongs(t *testing.T) {
func TestMConnectionStopsAndReturnsError(t *testing.T) {
server, client := NetPipe()
defer server.Close() // nolint: errcheck
defer client.Close() // nolint: errcheck
defer server.Close()
defer client.Close()
receivedCh := make(chan []byte)
errorsCh := make(chan interface{})
@ -378,7 +378,7 @@ func TestMConnectionStopsAndReturnsError(t *testing.T) {
mconn := createMConnectionWithCallbacks(client, onReceive, onError)
err := mconn.Start()
require.Nil(t, err)
defer mconn.Stop()
defer mconn.Stop() // nolint:errcheck // ignore for tests
if err := client.Close(); err != nil {
t.Error(err)
@ -437,8 +437,8 @@ func expectSend(ch chan struct{}) bool {
func TestMConnectionReadErrorBadEncoding(t *testing.T) {
chOnErr := make(chan struct{})
mconnClient, mconnServer := newClientAndServerConnsForReadErrors(t, chOnErr)
defer mconnClient.Stop()
defer mconnServer.Stop()
defer mconnClient.Stop() // nolint:errcheck // ignore for tests
defer mconnServer.Stop() // nolint:errcheck // ignore for tests
client := mconnClient.conn
@ -470,8 +470,8 @@ func TestMConnectionReadErrorLongMessage(t *testing.T) {
chOnRcv := make(chan struct{})
mconnClient, mconnServer := newClientAndServerConnsForReadErrors(t, chOnErr)
defer mconnClient.Stop()
defer mconnServer.Stop()
defer mconnClient.Stop() // nolint:errcheck // ignore for tests
defer mconnServer.Stop() // nolint:errcheck // ignore for tests
mconnServer.onReceive = func(chID byte, msgBytes []byte) {
chOnRcv <- struct{}{}
@ -506,8 +506,8 @@ func TestMConnectionReadErrorLongMessage(t *testing.T) {
func TestMConnectionReadErrorUnknownMsgType(t *testing.T) {
chOnErr := make(chan struct{})
mconnClient, mconnServer := newClientAndServerConnsForReadErrors(t, chOnErr)
defer mconnClient.Stop()
defer mconnServer.Stop()
defer mconnClient.Stop() // nolint:errcheck // ignore for tests
defer mconnServer.Stop() // nolint:errcheck // ignore for tests
// send msg with unknown msg type
_, err := protoio.NewDelimitedWriter(mconnClient.conn).WriteMsg(&types.Header{ChainID: "x"})
@ -523,7 +523,7 @@ func TestMConnectionTrySend(t *testing.T) {
mconn := createTestMConnection(client)
err := mconn.Start()
require.Nil(t, err)
defer mconn.Stop()
defer mconn.Stop() // nolint:errcheck // ignore for tests
msg := []byte("Semicolon-Woman")
resultCh := make(chan string, 2)


+ 1
- 1
p2p/fuzz.go View File

@ -123,7 +123,7 @@ func (fc *FuzzedConnection) fuzz() bool {
case r < fc.config.ProbDropRW+fc.config.ProbDropConn:
// XXX: can't this fail because machine precision?
// XXX: do we need an error?
fc.Close() // nolint: errcheck, gas
fc.Close()
return true
case r < fc.config.ProbDropRW+fc.config.ProbDropConn+fc.config.ProbSleep:
time.Sleep(fc.randomDuration())


+ 1
- 1
p2p/peer.go View File

@ -320,7 +320,7 @@ func (p *peer) CloseConn() error {
// CloseConn closes the underlying connection
func (pc *peerConn) CloseConn() {
pc.conn.Close() // nolint: errcheck
pc.conn.Close()
}
// RemoteAddr returns peer's remote network address.


+ 1
- 1
p2p/pex/file.go View File

@ -55,7 +55,7 @@ func (a *addrBook) loadFromFile(filePath string) bool {
if err != nil {
panic(fmt.Sprintf("Error opening file %s: %v", filePath, err))
}
defer r.Close() // nolint: errcheck
defer r.Close()
aJSON := &addrBookJSON{}
dec := json.NewDecoder(r)
err = dec.Decode(aJSON)


+ 38
- 30
p2p/pex/pex_reactor_test.go View File

@ -73,7 +73,7 @@ func TestPEXReactorRunning(t *testing.T) {
// directory to store address books
dir, err := ioutil.TempDir("", "pex_reactor")
require.Nil(t, err)
defer os.RemoveAll(dir) // nolint: errcheck
defer os.RemoveAll(dir)
books := make([]AddrBook, N)
logger := log.TestingLogger()
@ -98,7 +98,8 @@ func TestPEXReactorRunning(t *testing.T) {
addOtherNodeAddrToAddrBook := func(switchIndex, otherSwitchIndex int) {
addr := switches[otherSwitchIndex].NetAddress()
books[switchIndex].AddAddress(addr, addr)
err := books[switchIndex].AddAddress(addr, addr)
require.NoError(t, err)
}
addOtherNodeAddrToAddrBook(0, 1)
@ -114,7 +115,8 @@ func TestPEXReactorRunning(t *testing.T) {
// stop them
for _, s := range switches {
s.Stop()
err := s.Stop()
require.NoError(t, err)
}
}
@ -147,7 +149,8 @@ func TestPEXReactorRequestMessageAbuse(t *testing.T) {
peerAddr := peer.SocketAddr()
p2p.AddPeerToSwitchPeerSet(sw, peer)
assert.True(t, sw.Peers().Has(peer.ID()))
book.AddAddress(peerAddr, peerAddr)
err := book.AddAddress(peerAddr, peerAddr)
require.NoError(t, err)
require.True(t, book.HasAddress(peerAddr))
id := string(peer.ID())
@ -205,12 +208,12 @@ func TestCheckSeeds(t *testing.T) {
// directory to store address books
dir, err := ioutil.TempDir("", "pex_reactor")
require.Nil(t, err)
defer os.RemoveAll(dir) // nolint: errcheck
defer os.RemoveAll(dir)
// 1. test creating peer with no seeds works
peerSwitch := testCreateDefaultPeer(dir, 0)
require.Nil(t, peerSwitch.Start())
peerSwitch.Stop()
peerSwitch.Stop() // nolint:errcheck // ignore for tests
// 2. create seed
seed := testCreateSeed(dir, 1, []*p2p.NetAddress{}, []*p2p.NetAddress{})
@ -218,7 +221,7 @@ func TestCheckSeeds(t *testing.T) {
// 3. test create peer with online seed works
peerSwitch = testCreatePeerWithSeed(dir, 2, seed)
require.Nil(t, peerSwitch.Start())
peerSwitch.Stop()
peerSwitch.Stop() // nolint:errcheck // ignore for tests
// 4. test create peer with all seeds having unresolvable DNS fails
badPeerConfig := &ReactorConfig{
@ -227,7 +230,7 @@ func TestCheckSeeds(t *testing.T) {
}
peerSwitch = testCreatePeerWithConfig(dir, 2, badPeerConfig)
require.Error(t, peerSwitch.Start())
peerSwitch.Stop()
peerSwitch.Stop() // nolint:errcheck // ignore for tests
// 5. test create peer with one good seed address succeeds
badPeerConfig = &ReactorConfig{
@ -237,24 +240,24 @@ func TestCheckSeeds(t *testing.T) {
}
peerSwitch = testCreatePeerWithConfig(dir, 2, badPeerConfig)
require.Nil(t, peerSwitch.Start())
peerSwitch.Stop()
peerSwitch.Stop() // nolint:errcheck // ignore for tests
}
func TestPEXReactorUsesSeedsIfNeeded(t *testing.T) {
// directory to store address books
dir, err := ioutil.TempDir("", "pex_reactor")
require.Nil(t, err)
defer os.RemoveAll(dir) // nolint: errcheck
defer os.RemoveAll(dir)
// 1. create seed
seed := testCreateSeed(dir, 0, []*p2p.NetAddress{}, []*p2p.NetAddress{})
require.Nil(t, seed.Start())
defer seed.Stop()
defer seed.Stop() // nolint:errcheck // ignore for tests
// 2. create usual peer with only seed configured.
peer := testCreatePeerWithSeed(dir, 1, seed)
require.Nil(t, peer.Start())
defer peer.Stop()
defer peer.Stop() // nolint:errcheck // ignore for tests
// 3. check that the peer connects to seed immediately
assertPeersWithTimeout(t, []*p2p.Switch{peer}, 10*time.Millisecond, 3*time.Second, 1)
@ -264,23 +267,23 @@ func TestConnectionSpeedForPeerReceivedFromSeed(t *testing.T) {
// directory to store address books
dir, err := ioutil.TempDir("", "pex_reactor")
require.Nil(t, err)
defer os.RemoveAll(dir) // nolint: errcheck
defer os.RemoveAll(dir)
// 1. create peer
peerSwitch := testCreateDefaultPeer(dir, 1)
require.Nil(t, peerSwitch.Start())
defer peerSwitch.Stop()
defer peerSwitch.Stop() // nolint:errcheck // ignore for tests
// 2. Create seed which knows about the peer
peerAddr := peerSwitch.NetAddress()
seed := testCreateSeed(dir, 2, []*p2p.NetAddress{peerAddr}, []*p2p.NetAddress{peerAddr})
require.Nil(t, seed.Start())
defer seed.Stop()
defer seed.Stop() // nolint:errcheck // ignore for tests
// 3. create another peer with only seed configured.
secondPeer := testCreatePeerWithSeed(dir, 3, seed)
require.Nil(t, secondPeer.Start())
defer secondPeer.Stop()
defer secondPeer.Stop() // nolint:errcheck // ignore for tests
// 4. check that the second peer connects to seed immediately
assertPeersWithTimeout(t, []*p2p.Switch{secondPeer}, 10*time.Millisecond, 3*time.Second, 1)
@ -293,7 +296,7 @@ func TestPEXReactorSeedMode(t *testing.T) {
// directory to store address books
dir, err := ioutil.TempDir("", "pex_reactor")
require.Nil(t, err)
defer os.RemoveAll(dir) // nolint: errcheck
defer os.RemoveAll(dir)
pexRConfig := &ReactorConfig{SeedMode: true, SeedDisconnectWaitPeriod: 10 * time.Millisecond}
pexR, book := createReactor(pexRConfig)
@ -303,13 +306,13 @@ func TestPEXReactorSeedMode(t *testing.T) {
sw.SetAddrBook(book)
err = sw.Start()
require.NoError(t, err)
defer sw.Stop()
defer sw.Stop() // nolint:errcheck // ignore for tests
assert.Zero(t, sw.Peers().Size())
peerSwitch := testCreateDefaultPeer(dir, 1)
require.NoError(t, peerSwitch.Start())
defer peerSwitch.Stop()
defer peerSwitch.Stop() // nolint:errcheck // ignore for tests
// 1. Test crawlPeers dials the peer
pexR.crawlPeers([]*p2p.NetAddress{peerSwitch.NetAddress()})
@ -332,7 +335,7 @@ func TestPEXReactorDoesNotDisconnectFromPersistentPeerInSeedMode(t *testing.T) {
// directory to store address books
dir, err := ioutil.TempDir("", "pex_reactor")
require.Nil(t, err)
defer os.RemoveAll(dir) // nolint: errcheck
defer os.RemoveAll(dir)
pexRConfig := &ReactorConfig{SeedMode: true, SeedDisconnectWaitPeriod: 1 * time.Millisecond}
pexR, book := createReactor(pexRConfig)
@ -342,13 +345,13 @@ func TestPEXReactorDoesNotDisconnectFromPersistentPeerInSeedMode(t *testing.T) {
sw.SetAddrBook(book)
err = sw.Start()
require.NoError(t, err)
defer sw.Stop()
defer sw.Stop() // nolint:errcheck // ignore for tests
assert.Zero(t, sw.Peers().Size())
peerSwitch := testCreateDefaultPeer(dir, 1)
require.NoError(t, peerSwitch.Start())
defer peerSwitch.Stop()
defer peerSwitch.Stop() // nolint:errcheck // ignore for tests
err = sw.AddPersistentPeers([]string{peerSwitch.NetAddress().String()})
require.NoError(t, err)
@ -370,7 +373,7 @@ func TestPEXReactorDialsPeerUpToMaxAttemptsInSeedMode(t *testing.T) {
// directory to store address books
dir, err := ioutil.TempDir("", "pex_reactor")
require.Nil(t, err)
defer os.RemoveAll(dir) // nolint: errcheck
defer os.RemoveAll(dir)
pexR, book := createReactor(&ReactorConfig{SeedMode: true})
defer teardownReactor(book)
@ -406,7 +409,7 @@ func TestPEXReactorSeedModeFlushStop(t *testing.T) {
// directory to store address books
dir, err := ioutil.TempDir("", "pex_reactor")
require.Nil(t, err)
defer os.RemoveAll(dir) // nolint: errcheck
defer os.RemoveAll(dir)
books := make([]AddrBook, N)
logger := log.TestingLogger()
@ -460,12 +463,14 @@ func TestPEXReactorSeedModeFlushStop(t *testing.T) {
// it should be safe to do this.
peers := switches[0].Peers().List()
for _, peer := range peers {
peer.Stop()
err := peer.Stop()
require.NoError(t, err)
}
// stop the switches
for _, s := range switches {
s.Stop()
err := s.Stop()
require.NoError(t, err)
}
}
@ -501,12 +506,14 @@ func TestPEXReactorDialPeer(t *testing.T) {
assert.Equal(t, 0, pexR.AttemptsToDial(addr))
// 1st unsuccessful attempt
pexR.dialPeer(addr)
err := pexR.dialPeer(addr)
require.Error(t, err)
assert.Equal(t, 1, pexR.AttemptsToDial(addr))
// 2nd unsuccessful attempt
pexR.dialPeer(addr)
err = pexR.dialPeer(addr)
require.Error(t, err)
// must be skipped because it is too early
assert.Equal(t, 1, pexR.AttemptsToDial(addr))
@ -515,7 +522,8 @@ func TestPEXReactorDialPeer(t *testing.T) {
time.Sleep(3 * time.Second)
// 3rd attempt
pexR.dialPeer(addr)
err = pexR.dialPeer(addr)
require.Error(t, err)
assert.Equal(t, 2, pexR.AttemptsToDial(addr))
}
@ -609,7 +617,7 @@ func testCreateSeed(dir string, id int, knownAddrs, srcAddrs []*p2p.NetAddress)
book := NewAddrBook(filepath.Join(dir, "addrbookSeed.json"), false)
book.SetLogger(log.TestingLogger())
for j := 0; j < len(knownAddrs); j++ {
book.AddAddress(knownAddrs[j], srcAddrs[j])
book.AddAddress(knownAddrs[j], srcAddrs[j]) // nolint:errcheck // ignore for tests
book.MarkGood(knownAddrs[j].ID)
}
sw.SetAddrBook(book)


+ 5
- 5
p2p/upnp/upnp.go View File

@ -46,7 +46,7 @@ func Discover() (nat NAT, err error) {
return
}
socket := conn.(*net.UDPConn)
defer socket.Close() // nolint: errcheck
defer socket.Close()
if err := socket.SetDeadline(time.Now().Add(3 * time.Second)); err != nil {
return nil, err
@ -206,7 +206,7 @@ func getServiceURL(rootURL string) (url, urnDomain string, err error) {
if err != nil {
return
}
defer r.Body.Close() // nolint: errcheck
defer r.Body.Close()
if r.StatusCode >= 400 {
err = errors.New(string(r.StatusCode))
@ -306,7 +306,7 @@ func (n *upnpNAT) getExternalIPAddress() (info statusInfo, err error) {
var response *http.Response
response, err = soapRequest(n.serviceURL, "GetExternalIPAddress", message, n.urnDomain)
if response != nil {
defer response.Body.Close() // nolint: errcheck
defer response.Body.Close()
}
if err != nil {
return
@ -365,7 +365,7 @@ func (n *upnpNAT) AddPortMapping(
var response *http.Response
response, err = soapRequest(n.serviceURL, "AddPortMapping", message, n.urnDomain)
if response != nil {
defer response.Body.Close() // nolint: errcheck
defer response.Body.Close()
}
if err != nil {
return
@ -391,7 +391,7 @@ func (n *upnpNAT) DeletePortMapping(protocol string, externalPort, internalPort
var response *http.Response
response, err = soapRequest(n.serviceURL, "DeletePortMapping", message, n.urnDomain)
if response != nil {
defer response.Body.Close() // nolint: errcheck
defer response.Body.Close()
}
if err != nil {
return


+ 2
- 2
rpc/client/mock/abci.go View File

@ -61,7 +61,7 @@ func (a ABCIApp) BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error
c := a.App.CheckTx(abci.RequestCheckTx{Tx: tx})
// and this gets written in a background thread...
if !c.IsErr() {
go func() { a.App.DeliverTx(abci.RequestDeliverTx{Tx: tx}) }() // nolint: errcheck
go func() { a.App.DeliverTx(abci.RequestDeliverTx{Tx: tx}) }()
}
return &ctypes.ResultBroadcastTx{
Code: c.Code,
@ -76,7 +76,7 @@ func (a ABCIApp) BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error)
c := a.App.CheckTx(abci.RequestCheckTx{Tx: tx})
// and this gets written in a background thread...
if !c.IsErr() {
go func() { a.App.DeliverTx(abci.RequestDeliverTx{Tx: tx}) }() // nolint: errcheck
go func() { a.App.DeliverTx(abci.RequestDeliverTx{Tx: tx}) }()
}
return &ctypes.ResultBroadcastTx{
Code: c.Code,


+ 2
- 2
rpc/jsonrpc/client/http_json_client.go View File

@ -177,7 +177,7 @@ func (c *Client) Call(method string, params map[string]interface{}, result inter
if err != nil {
return nil, fmt.Errorf("post failed: %w", err)
}
defer httpResponse.Body.Close() // nolint: errcheck
defer httpResponse.Body.Close()
responseBytes, err := ioutil.ReadAll(httpResponse.Body)
if err != nil {
@ -221,7 +221,7 @@ func (c *Client) sendBatch(requests []*jsonRPCBufferedRequest) ([]interface{}, e
if err != nil {
return nil, fmt.Errorf("post failed: %w", err)
}
defer httpResponse.Body.Close() // nolint: errcheck
defer httpResponse.Body.Close()
responseBytes, err := ioutil.ReadAll(httpResponse.Body)
if err != nil {


+ 1
- 1
rpc/jsonrpc/client/http_uri_client.go View File

@ -59,7 +59,7 @@ func (c *URIClient) Call(method string, params map[string]interface{}, result in
if err != nil {
return nil, fmt.Errorf("post form failed: %w", err)
}
defer resp.Body.Close() // nolint: errcheck
defer resp.Body.Close()
responseBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {


+ 7
- 6
rpc/jsonrpc/client/ws_client_test.go View File

@ -34,7 +34,7 @@ func (h *myHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if err != nil {
panic(err)
}
defer conn.Close() // nolint: errcheck
defer conn.Close()
for {
messageType, in, err := conn.ReadMessage()
if err != nil {
@ -72,7 +72,7 @@ func TestWSClientReconnectsAfterReadFailure(t *testing.T) {
defer s.Close()
c := startClient(t, "//"+s.Listener.Addr().String())
defer c.Stop()
defer c.Stop() // nolint:errcheck // ignore for tests
wg.Add(1)
go callWgDoneOnResult(t, c, &wg)
@ -104,7 +104,7 @@ func TestWSClientReconnectsAfterWriteFailure(t *testing.T) {
s := httptest.NewServer(h)
c := startClient(t, "//"+s.Listener.Addr().String())
defer c.Stop()
defer c.Stop() // nolint:errcheck // ignore for tests
wg.Add(2)
go callWgDoneOnResult(t, c, &wg)
@ -132,7 +132,7 @@ func TestWSClientReconnectFailure(t *testing.T) {
s := httptest.NewServer(h)
c := startClient(t, "//"+s.Listener.Addr().String())
defer c.Stop()
defer c.Stop() // nolint:errcheck // ignore for tests
go func() {
for {
@ -181,14 +181,15 @@ func TestNotBlockingOnStop(t *testing.T) {
timeout := 2 * time.Second
s := httptest.NewServer(&myHandler{})
c := startClient(t, "//"+s.Listener.Addr().String())
c.Call(context.Background(), "a", make(map[string]interface{}))
c.Call(context.Background(), "a", make(map[string]interface{})) // nolint:errcheck // ignore for tests
// Let the readRoutine get around to blocking
time.Sleep(time.Second)
passCh := make(chan struct{})
go func() {
// Unless we have a non-blocking write to ResponsesCh from readRoutine
// this blocks forever ont the waitgroup
c.Stop()
err := c.Stop()
require.NoError(t, err)
passCh <- struct{}{}
}()
select {


+ 3
- 2
rpc/jsonrpc/server/http_server_test.go View File

@ -37,7 +37,7 @@ func TestMaxOpenConnections(t *testing.T) {
l, err := Listen("tcp://127.0.0.1:0", config)
require.NoError(t, err)
defer l.Close()
go Serve(l, mux, log.TestingLogger(), config)
go Serve(l, mux, log.TestingLogger(), config) //nolint:errcheck // ignore for tests
// Make N GET calls to the server.
attempts := max * 2
@ -55,7 +55,8 @@ func TestMaxOpenConnections(t *testing.T) {
return
}
defer r.Body.Close()
io.Copy(ioutil.Discard, r.Body)
_, err = io.Copy(ioutil.Discard, r.Body)
require.NoError(t, err)
}()
}
wg.Wait()


+ 4
- 1
rpc/jsonrpc/test/main.go View File

@ -38,5 +38,8 @@ func main() {
if err != nil {
tmos.Exit(err.Error())
}
rpcserver.Serve(listener, mux, logger, config)
if err = rpcserver.Serve(listener, mux, logger, config); err != nil {
tmos.Exit(err.Error())
}
}

+ 1
- 1
scripts/wal2json/main.go View File

@ -48,7 +48,7 @@ func main() {
}
if err == nil {
if endMsg, ok := msg.Msg.(cs.EndHeightMessage); ok {
_, err = os.Stdout.Write([]byte(fmt.Sprintf("ENDHEIGHT %d\n", endMsg.Height))) // nolint: errcheck, gas
_, err = os.Stdout.Write([]byte(fmt.Sprintf("ENDHEIGHT %d\n", endMsg.Height)))
}
}
if err != nil {


+ 7
- 6
state/execution_test.go View File

@ -32,7 +32,7 @@ func TestApplyBlock(t *testing.T) {
proxyApp := proxy.NewAppConns(cc)
err := proxyApp.Start()
require.Nil(t, err)
defer proxyApp.Stop()
defer proxyApp.Stop() //nolint:errcheck // ignore for tests
state, stateDB, _ := makeState(1, 1)
@ -57,7 +57,7 @@ func TestBeginBlockValidators(t *testing.T) {
proxyApp := proxy.NewAppConns(cc)
err := proxyApp.Start()
require.Nil(t, err)
defer proxyApp.Stop()
defer proxyApp.Stop() //nolint:errcheck // no need to check error again
state, stateDB, _ := makeState(2, 2)
@ -119,7 +119,7 @@ func TestBeginBlockByzantineValidators(t *testing.T) {
proxyApp := proxy.NewAppConns(cc)
err := proxyApp.Start()
require.Nil(t, err)
defer proxyApp.Stop()
defer proxyApp.Stop() //nolint:errcheck // ignore for tests
state, stateDB, privVals := makeState(2, 12)
@ -308,7 +308,7 @@ func TestEndBlockValidatorUpdates(t *testing.T) {
proxyApp := proxy.NewAppConns(cc)
err := proxyApp.Start()
require.Nil(t, err)
defer proxyApp.Stop()
defer proxyApp.Stop() //nolint:errcheck // ignore for tests
state, stateDB, _ := makeState(1, 1)
@ -323,7 +323,8 @@ func TestEndBlockValidatorUpdates(t *testing.T) {
eventBus := types.NewEventBus()
err = eventBus.Start()
require.NoError(t, err)
defer eventBus.Stop()
defer eventBus.Stop() //nolint:errcheck // ignore for tests
blockExec.SetEventBus(eventBus)
updatesSub, err := eventBus.Subscribe(
@ -377,7 +378,7 @@ func TestEndBlockValidatorUpdatesResultingInEmptySet(t *testing.T) {
proxyApp := proxy.NewAppConns(cc)
err := proxyApp.Start()
require.Nil(t, err)
defer proxyApp.Stop()
defer proxyApp.Stop() //nolint:errcheck // ignore for tests
state, stateDB, _ := makeState(1, 1)
blockExec := sm.NewBlockExecutor(


+ 1
- 1
state/txindex/kv/kv_test.go View File

@ -327,7 +327,7 @@ func txResultWithEvents(events []abci.Event) *abci.TxResult {
func benchmarkTxIndex(txsCount int64, b *testing.B) {
dir, err := ioutil.TempDir("", "tx_index_db")
require.NoError(b, err)
defer os.RemoveAll(dir) // nolint: errcheck
defer os.RemoveAll(dir)
store, err := db.NewDB("tx_index", "goleveldb", dir)
require.NoError(b, err)


+ 5
- 4
state/validation_test.go View File

@ -29,7 +29,7 @@ var defaultTestTime = time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC)
func TestValidateBlockHeader(t *testing.T) {
proxyApp := newTestApp()
require.NoError(t, proxyApp.Start())
defer proxyApp.Stop()
defer proxyApp.Stop() //nolint:errcheck // ignore for tests
state, stateDB, privVals := makeState(3, 1)
blockExec := sm.NewBlockExecutor(
@ -99,7 +99,7 @@ func TestValidateBlockHeader(t *testing.T) {
func TestValidateBlockCommit(t *testing.T) {
proxyApp := newTestApp()
require.NoError(t, proxyApp.Start())
defer proxyApp.Stop()
defer proxyApp.Stop() //nolint:errcheck // ignore for tests
state, stateDB, privVals := makeState(1, 1)
blockExec := sm.NewBlockExecutor(
@ -212,7 +212,7 @@ func TestValidateBlockCommit(t *testing.T) {
func TestValidateBlockEvidence(t *testing.T) {
proxyApp := newTestApp()
require.NoError(t, proxyApp.Start())
defer proxyApp.Stop()
defer proxyApp.Stop() //nolint:errcheck // ignore for tests
state, stateDB, privVals := makeState(4, 1)
state.ConsensusParams.Evidence.MaxNum = 3
@ -669,7 +669,8 @@ func TestVerifyEvidenceWithPhantomValidatorEvidence(t *testing.T) {
bz, err := valInfo.Marshal()
require.NoError(t, err)
stateDB.Set(valKey, bz)
err = stateDB.Set(valKey, bz)
require.NoError(t, err)
ev = &types.PhantomValidatorEvidence{
Vote: vote2,
LastHeightValidatorWasInSet: 2,


+ 6
- 3
store/store_test.go View File

@ -178,7 +178,8 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) {
incompletePartSet := types.NewPartSetFromHeader(types.PartSetHeader{Total: 2})
uncontiguousPartSet := types.NewPartSetFromHeader(types.PartSetHeader{Total: 0})
uncontiguousPartSet.AddPart(part2)
_, err := uncontiguousPartSet.AddPart(part2)
require.Error(t, err)
header1 := types.Header{
Height: 1,
@ -303,7 +304,8 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) {
bBlockMeta := bs.LoadBlockMeta(tuple.block.Height)
if tuple.eraseSeenCommitInDB {
db.Delete(calcSeenCommitKey(tuple.block.Height))
err := db.Delete(calcSeenCommitKey(tuple.block.Height))
require.NoError(t, err)
}
if tuple.corruptSeenCommitInDB {
err := db.Set(calcSeenCommitKey(tuple.block.Height), []byte("bogus-seen-commit"))
@ -313,7 +315,8 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) {
commitHeight := tuple.block.Height - 1
if tuple.eraseCommitInDB {
db.Delete(calcBlockCommitKey(commitHeight))
err := db.Delete(calcBlockCommitKey(commitHeight))
require.NoError(t, err)
}
if tuple.corruptCommitInDB {
err := db.Set(calcBlockCommitKey(commitHeight), []byte("foo-bogus"))


+ 1
- 1
tools/tm-signer-harness/internal/test_harness_test.go View File

@ -161,7 +161,7 @@ func harnessTest(t *testing.T, signerServerMaker func(th *TestHarness) *privval.
ss := signerServerMaker(th)
require.NoError(t, ss.Start())
assert.True(t, ss.IsRunning())
defer ss.Stop()
defer ss.Stop() //nolint:errcheck // ignore for tests
<-donec
assert.Equal(t, expectedExitCode, th.exitCode)


Loading…
Cancel
Save