mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-24 22:32:15 +00:00
parent
411bc5e49f
commit
f25d727035
@ -9,7 +9,6 @@ linters:
|
||||
- maligned
|
||||
- errcheck
|
||||
- staticcheck
|
||||
- dupl
|
||||
- ineffassign
|
||||
- interfacer
|
||||
- unconvert
|
||||
|
4
Makefile
4
Makefile
@ -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:
|
||||
|
@ -121,86 +121,75 @@ func TestDBIteratorNonemptyBeginAfter(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDBBatchWrite1(t *testing.T) {
|
||||
mdb := newMockDB()
|
||||
ddb := NewDebugDB(t.Name(), mdb)
|
||||
batch := ddb.NewBatch()
|
||||
|
||||
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()
|
||||
|
||||
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 TestDBBatchWrite2(t *testing.T) {
|
||||
mdb := newMockDB()
|
||||
ddb := NewDebugDB(t.Name(), mdb)
|
||||
batch := ddb.NewBatch()
|
||||
|
||||
},
|
||||
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()
|
||||
|
||||
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 TestDBBatchWriteSync1(t *testing.T) {
|
||||
mdb := newMockDB()
|
||||
ddb := NewDebugDB(t.Name(), mdb)
|
||||
batch := ddb.NewBatch()
|
||||
|
||||
},
|
||||
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()
|
||||
|
||||
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"])
|
||||
}
|
||||
|
||||
func TestDBBatchWriteSync2(t *testing.T) {
|
||||
mdb := newMockDB()
|
||||
ddb := NewDebugDB(t.Name(), mdb)
|
||||
batch := ddb.NewBatch()
|
||||
|
||||
},
|
||||
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()
|
||||
|
||||
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"])
|
||||
},
|
||||
map[string]int{
|
||||
"Set": 0, "SetSync": 0, "SetNoLock": 3, "SetNoLockSync": 0,
|
||||
"Delete": 0, "DeleteSync": 0, "DeleteNoLock": 0, "DeleteNoLockSync": 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
mdb := newMockDB()
|
||||
ddb := NewDebugDB(t.Name(), mdb)
|
||||
batch := ddb.NewBatch()
|
||||
|
||||
tc.modify(batch)
|
||||
|
||||
for call, exp := range tc.calls {
|
||||
got := mdb.calls[call]
|
||||
assert.Equal(t, exp, got, "#%v - key: %s", i, call)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
// 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
|
||||
// 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))
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, txres.Code, abci.CodeTypeOK)
|
||||
|
||||
// and wait for confirmation
|
||||
evt, err := client.WaitForOneEvent(c, evtTyp, waitForEventTimeout)
|
||||
|
Loading…
x
Reference in New Issue
Block a user