Browse Source

make dupl linter pass (#3385)

Refs #3262
pull/3387/head
Anton Kaliaev 6 years ago
committed by GitHub
parent
commit
f25d727035
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 90 additions and 120 deletions
  1. +0
    -1
      .golangci.yml
  2. +2
    -2
      Makefile
  3. +68
    -79
      libs/db/db_test.go
  4. +20
    -38
      rpc/client/event_test.go

+ 0
- 1
.golangci.yml View File

@ -9,7 +9,6 @@ linters:
- maligned
- errcheck
- staticcheck
- dupl
- ineffassign
- interfacer
- unconvert


+ 2
- 2
Makefile View File

@ -214,11 +214,11 @@ vagrant_test:
### go tests
test:
@echo "--> Running go test"
go test -p 1 $(PACKAGES)
@go test -p 1 $(PACKAGES)
test_race:
@echo "--> Running go test --race"
go test -p 1 -v -race $(PACKAGES)
@go test -p 1 -v -race $(PACKAGES)
# uses https://github.com/sasha-s/go-deadlock/ to detect potential deadlocks
test_with_deadlock:


+ 68
- 79
libs/db/db_test.go View File

@ -121,86 +121,75 @@ func TestDBIteratorNonemptyBeginAfter(t *testing.T) {
}
}
func TestDBBatchWrite1(t *testing.T) {
mdb := newMockDB()
ddb := NewDebugDB(t.Name(), mdb)
batch := ddb.NewBatch()
batch.Set(bz("1"), bz("1"))
batch.Set(bz("2"), bz("2"))
batch.Delete(bz("3"))
batch.Set(bz("4"), bz("4"))
batch.Write()
assert.Equal(t, 0, mdb.calls["Set"])
assert.Equal(t, 0, mdb.calls["SetSync"])
assert.Equal(t, 3, mdb.calls["SetNoLock"])
assert.Equal(t, 0, mdb.calls["SetNoLockSync"])
assert.Equal(t, 0, mdb.calls["Delete"])
assert.Equal(t, 0, mdb.calls["DeleteSync"])
assert.Equal(t, 1, mdb.calls["DeleteNoLock"])
assert.Equal(t, 0, mdb.calls["DeleteNoLockSync"])
}
func TestDBBatchWrite(t *testing.T) {
testCases := []struct {
modify func(batch Batch)
calls map[string]int
}{
0: {
func(batch Batch) {
batch.Set(bz("1"), bz("1"))
batch.Set(bz("2"), bz("2"))
batch.Delete(bz("3"))
batch.Set(bz("4"), bz("4"))
batch.Write()
},
map[string]int{
"Set": 0, "SetSync": 0, "SetNoLock": 3, "SetNoLockSync": 0,
"Delete": 0, "DeleteSync": 0, "DeleteNoLock": 1, "DeleteNoLockSync": 0,
},
},
1: {
func(batch Batch) {
batch.Set(bz("1"), bz("1"))
batch.Set(bz("2"), bz("2"))
batch.Set(bz("4"), bz("4"))
batch.Delete(bz("3"))
batch.Write()
},
map[string]int{
"Set": 0, "SetSync": 0, "SetNoLock": 3, "SetNoLockSync": 0,
"Delete": 0, "DeleteSync": 0, "DeleteNoLock": 1, "DeleteNoLockSync": 0,
},
},
2: {
func(batch Batch) {
batch.Set(bz("1"), bz("1"))
batch.Set(bz("2"), bz("2"))
batch.Delete(bz("3"))
batch.Set(bz("4"), bz("4"))
batch.WriteSync()
},
map[string]int{
"Set": 0, "SetSync": 0, "SetNoLock": 2, "SetNoLockSync": 1,
"Delete": 0, "DeleteSync": 0, "DeleteNoLock": 1, "DeleteNoLockSync": 0,
},
},
3: {
func(batch Batch) {
batch.Set(bz("1"), bz("1"))
batch.Set(bz("2"), bz("2"))
batch.Set(bz("4"), bz("4"))
batch.Delete(bz("3"))
batch.WriteSync()
},
map[string]int{
"Set": 0, "SetSync": 0, "SetNoLock": 3, "SetNoLockSync": 0,
"Delete": 0, "DeleteSync": 0, "DeleteNoLock": 0, "DeleteNoLockSync": 1,
},
},
}
func TestDBBatchWrite2(t *testing.T) {
mdb := newMockDB()
ddb := NewDebugDB(t.Name(), mdb)
batch := ddb.NewBatch()
batch.Set(bz("1"), bz("1"))
batch.Set(bz("2"), bz("2"))
batch.Set(bz("4"), bz("4"))
batch.Delete(bz("3"))
batch.Write()
assert.Equal(t, 0, mdb.calls["Set"])
assert.Equal(t, 0, mdb.calls["SetSync"])
assert.Equal(t, 3, mdb.calls["SetNoLock"])
assert.Equal(t, 0, mdb.calls["SetNoLockSync"])
assert.Equal(t, 0, mdb.calls["Delete"])
assert.Equal(t, 0, mdb.calls["DeleteSync"])
assert.Equal(t, 1, mdb.calls["DeleteNoLock"])
assert.Equal(t, 0, mdb.calls["DeleteNoLockSync"])
}
for i, tc := range testCases {
mdb := newMockDB()
ddb := NewDebugDB(t.Name(), mdb)
batch := ddb.NewBatch()
func TestDBBatchWriteSync1(t *testing.T) {
mdb := newMockDB()
ddb := NewDebugDB(t.Name(), mdb)
batch := ddb.NewBatch()
batch.Set(bz("1"), bz("1"))
batch.Set(bz("2"), bz("2"))
batch.Delete(bz("3"))
batch.Set(bz("4"), bz("4"))
batch.WriteSync()
assert.Equal(t, 0, mdb.calls["Set"])
assert.Equal(t, 0, mdb.calls["SetSync"])
assert.Equal(t, 2, mdb.calls["SetNoLock"])
assert.Equal(t, 1, mdb.calls["SetNoLockSync"])
assert.Equal(t, 0, mdb.calls["Delete"])
assert.Equal(t, 0, mdb.calls["DeleteSync"])
assert.Equal(t, 1, mdb.calls["DeleteNoLock"])
assert.Equal(t, 0, mdb.calls["DeleteNoLockSync"])
}
tc.modify(batch)
func TestDBBatchWriteSync2(t *testing.T) {
mdb := newMockDB()
ddb := NewDebugDB(t.Name(), mdb)
batch := ddb.NewBatch()
batch.Set(bz("1"), bz("1"))
batch.Set(bz("2"), bz("2"))
batch.Set(bz("4"), bz("4"))
batch.Delete(bz("3"))
batch.WriteSync()
assert.Equal(t, 0, mdb.calls["Set"])
assert.Equal(t, 0, mdb.calls["SetSync"])
assert.Equal(t, 3, mdb.calls["SetNoLock"])
assert.Equal(t, 0, mdb.calls["SetNoLockSync"])
assert.Equal(t, 0, mdb.calls["Delete"])
assert.Equal(t, 0, mdb.calls["DeleteSync"])
assert.Equal(t, 0, mdb.calls["DeleteNoLock"])
assert.Equal(t, 1, mdb.calls["DeleteNoLockSync"])
for call, exp := range tc.calls {
got := mdb.calls[call]
assert.Equal(t, exp, got, "#%v - key: %s", i, call)
}
}
}

+ 20
- 38
rpc/client/event_test.go View File

@ -1,6 +1,7 @@
package client_test
import (
"fmt"
"reflect"
"testing"
"time"
@ -10,6 +11,7 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/rpc/client"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/types"
)
@ -78,7 +80,10 @@ func TestBlockEvents(t *testing.T) {
}
}
func TestTxEventsSentWithBroadcastTxAsync(t *testing.T) {
func TestTxEventsSentWithBroadcastTxAsync(t *testing.T) { testTxEventsSent(t, "async") }
func TestTxEventsSentWithBroadcastTxSync(t *testing.T) { testTxEventsSent(t, "sync") }
func testTxEventsSent(t *testing.T, broadcastMethod string) {
for i, c := range GetClients() {
i, c := i, c // capture params
t.Run(reflect.TypeOf(c).String(), func(t *testing.T) {
@ -95,45 +100,22 @@ func TestTxEventsSentWithBroadcastTxAsync(t *testing.T) {
_, _, tx := MakeTxKV()
evtTyp := types.EventTx
// send async
txres, err := c.BroadcastTxAsync(tx)
require.Nil(t, err, "%+v", err)
require.Equal(t, txres.Code, abci.CodeTypeOK) // FIXME
// and wait for confirmation
evt, err := client.WaitForOneEvent(c, evtTyp, waitForEventTimeout)
require.Nil(t, err, "%d: %+v", i, err)
// and make sure it has the proper info
txe, ok := evt.(types.EventDataTx)
require.True(t, ok, "%d: %#v", i, evt)
// make sure this is the proper tx
require.EqualValues(t, tx, txe.Tx)
require.True(t, txe.Result.IsOK())
})
}
}
func TestTxEventsSentWithBroadcastTxSync(t *testing.T) {
for i, c := range GetClients() {
i, c := i, c // capture params
t.Run(reflect.TypeOf(c).String(), func(t *testing.T) {
// start for this test it if it wasn't already running
if !c.IsRunning() {
// if so, then we start it, listen, and stop it.
err := c.Start()
require.Nil(t, err, "%d: %+v", i, err)
defer c.Stop()
// send
var (
txres *ctypes.ResultBroadcastTx
err error
)
switch broadcastMethod {
case "async":
txres, err = c.BroadcastTxAsync(tx)
case "sync":
txres, err = c.BroadcastTxSync(tx)
default:
panic(fmt.Sprintf("Unknown broadcastMethod %s", broadcastMethod))
}
// make the tx
_, _, tx := MakeTxKV()
evtTyp := types.EventTx
// send sync
txres, err := c.BroadcastTxSync(tx)
require.Nil(t, err, "%+v", err)
require.Equal(t, txres.Code, abci.CodeTypeOK) // FIXME
require.NoError(t, err)
require.Equal(t, txres.Code, abci.CodeTypeOK)
// and wait for confirmation
evt, err := client.WaitForOneEvent(c, evtTyp, waitForEventTimeout)


Loading…
Cancel
Save