mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-20 23:14:37 +00:00
rpc/test: wait for mempool CheckTx callback (#4908)
Fixes race conditions causing the following test failures:
```
=== RUN TestUnconfirmedTxs
TestUnconfirmedTxs: rpc_test.go:342:
Error Trace: rpc_test.go:342
Error: Not equal:
expected: 1
actual : 0
Test: TestUnconfirmedTxs
TestUnconfirmedTxs: rpc_test.go:343:
Error Trace: rpc_test.go:343
Error: Not equal:
expected: 1
actual : 0
Test: TestUnconfirmedTxs
TestUnconfirmedTxs: rpc_test.go:345:
Error Trace: rpc_test.go:345
Error: Not equal:
expected: types.Txs{types.Tx{0x39, 0x44, 0x4d, 0x6c, 0x4b, 0x66, 0x46, 0x78, 0x3d, 0x45, 0x33, 0x33, 0x68, 0x47, 0x6e, 0x79, 0x58}}
actual : types.Txs(nil)
Diff:
--- Expected
+++ Actual
@@ -1,4 +1,2 @@
-(types.Txs) (len=1) {
- (types.Tx) (len=17) Tx{39444D6C4B6646783D45333368476E7958}
-}
+(types.Txs) <nil>
Test: TestUnconfirmedTxs
TestUnconfirmedTxs: rpc_test.go:342:
Error Trace: rpc_test.go:342
Error: Not equal:
expected: 1
actual : 0
Test: TestUnconfirmedTxs
TestUnconfirmedTxs: rpc_test.go:343:
Error Trace: rpc_test.go:343
Error: Not equal:
expected: 1
actual : 0
Test: TestUnconfirmedTxs
TestUnconfirmedTxs: rpc_test.go:345:
Error Trace: rpc_test.go:345
Error: Not equal:
expected: types.Txs{types.Tx{0x39, 0x44, 0x4d, 0x6c, 0x4b, 0x66, 0x46, 0x78, 0x3d, 0x45, 0x33, 0x33, 0x68, 0x47, 0x6e, 0x79, 0x58}}
actual : types.Txs{}
Diff:
--- Expected
+++ Actual
@@ -1,3 +1,2 @@
-(types.Txs) (len=1) {
- (types.Tx) (len=17) Tx{39444D6C4B6646783D45333368476E7958}
+(types.Txs) {
}
Test: TestUnconfirmedTxs
--- FAIL: TestUnconfirmedTxs (0.20s)
=== RUN TestNumUnconfirmedTxs
TestNumUnconfirmedTxs: rpc_test.go:364:
Error Trace: rpc_test.go:364
Error: Not equal:
expected: 1
actual : 0
Test: TestNumUnconfirmedTxs
TestNumUnconfirmedTxs: rpc_test.go:365:
Error Trace: rpc_test.go:365
Error: Not equal:
expected: 1
actual : 0
Test: TestNumUnconfirmedTxs
TestNumUnconfirmedTxs: rpc_test.go:364:
Error Trace: rpc_test.go:364
Error: Not equal:
expected: 1
actual : 0
Test: TestNumUnconfirmedTxs
TestNumUnconfirmedTxs: rpc_test.go:365:
Error Trace: rpc_test.go:365
Error: Not equal:
expected: 1
actual : 0
Test: TestNumUnconfirmedTxs
--- FAIL: TestNumUnconfirmedTxs (0.09s)
```
This commit is contained in:
+25
-7
@@ -7,6 +7,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@@ -331,14 +332,22 @@ func TestBroadcastTxCommit(t *testing.T) {
|
|||||||
func TestUnconfirmedTxs(t *testing.T) {
|
func TestUnconfirmedTxs(t *testing.T) {
|
||||||
_, _, tx := MakeTxKV()
|
_, _, tx := MakeTxKV()
|
||||||
|
|
||||||
|
ch := make(chan *abci.Response, 1)
|
||||||
mempool := node.Mempool()
|
mempool := node.Mempool()
|
||||||
_ = mempool.CheckTx(tx, nil, mempl.TxInfo{})
|
err := mempool.CheckTx(tx, func(resp *abci.Response) { ch <- resp }, mempl.TxInfo{})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
for i, c := range GetClients() {
|
// wait for tx to arrive in mempoool.
|
||||||
mc, ok := c.(client.MempoolClient)
|
select {
|
||||||
require.True(t, ok, "%d", i)
|
case <-ch:
|
||||||
|
case <-time.After(5 * time.Second):
|
||||||
|
t.Error("Timed out waiting for CheckTx callback")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range GetClients() {
|
||||||
|
mc := c.(client.MempoolClient)
|
||||||
res, err := mc.UnconfirmedTxs(1)
|
res, err := mc.UnconfirmedTxs(1)
|
||||||
require.Nil(t, err, "%d: %+v", i, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, 1, res.Count)
|
assert.Equal(t, 1, res.Count)
|
||||||
assert.Equal(t, 1, res.Total)
|
assert.Equal(t, 1, res.Total)
|
||||||
@@ -352,10 +361,19 @@ func TestUnconfirmedTxs(t *testing.T) {
|
|||||||
func TestNumUnconfirmedTxs(t *testing.T) {
|
func TestNumUnconfirmedTxs(t *testing.T) {
|
||||||
_, _, tx := MakeTxKV()
|
_, _, tx := MakeTxKV()
|
||||||
|
|
||||||
|
ch := make(chan *abci.Response, 1)
|
||||||
mempool := node.Mempool()
|
mempool := node.Mempool()
|
||||||
_ = mempool.CheckTx(tx, nil, mempl.TxInfo{})
|
err := mempool.CheckTx(tx, func(resp *abci.Response) { ch <- resp }, mempl.TxInfo{})
|
||||||
mempoolSize := mempool.Size()
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// wait for tx to arrive in mempoool.
|
||||||
|
select {
|
||||||
|
case <-ch:
|
||||||
|
case <-time.After(5 * time.Second):
|
||||||
|
t.Error("Timed out waiting for CheckTx callback")
|
||||||
|
}
|
||||||
|
|
||||||
|
mempoolSize := mempool.Size()
|
||||||
for i, c := range GetClients() {
|
for i, c := range GetClients() {
|
||||||
mc, ok := c.(client.MempoolClient)
|
mc, ok := c.(client.MempoolClient)
|
||||||
require.True(t, ok, "%d", i)
|
require.True(t, ok, "%d", i)
|
||||||
|
|||||||
Reference in New Issue
Block a user