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
This commit is contained in:
Marko
2020-07-01 17:13:11 +02:00
committed by GitHub
parent 8ec8385427
commit 7e2cc1db5e
35 changed files with 289 additions and 200 deletions

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)
}
}