mirror of
https://github.com/tendermint/tendermint.git
synced 2026-08-21 22:56:22 +00:00
add allocate in Receive calls (#9667)
This commit is contained in:
@@ -191,7 +191,7 @@ func (memR *Reactor) ReceiveEnvelope(e p2p.Envelope) {
|
||||
}
|
||||
|
||||
func (memR *Reactor) Receive(chID byte, peer p2p.Peer, msgBytes []byte) {
|
||||
var msg *protomem.Message
|
||||
msg := &protomem.Message{}
|
||||
err := proto.Unmarshal(msgBytes, msg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/fortytw2/leaktest"
|
||||
"github.com/go-kit/log/term"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
@@ -293,6 +294,31 @@ func TestDontExhaustMaxActiveIDs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLegacyReactorReceiveBasic(t *testing.T) {
|
||||
config := cfg.TestConfig()
|
||||
const N = 1
|
||||
reactors := makeAndConnectReactors(config, N)
|
||||
var (
|
||||
reactor = reactors[0]
|
||||
peer = mock.NewPeer(nil)
|
||||
)
|
||||
defer func() {
|
||||
err := reactor.Stop()
|
||||
assert.NoError(t, err)
|
||||
}()
|
||||
|
||||
reactor.InitPeer(peer)
|
||||
reactor.AddPeer(peer)
|
||||
m := &memproto.Txs{}
|
||||
wm := m.Wrap()
|
||||
msg, err := proto.Marshal(wm)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.NotPanics(t, func() {
|
||||
reactor.Receive(mempool.MempoolChannel, peer, msg)
|
||||
})
|
||||
}
|
||||
|
||||
// mempoolLogger is a TestingLogger which uses a different
|
||||
// color for each validator ("validator" key must exist).
|
||||
func mempoolLogger() log.Logger {
|
||||
|
||||
@@ -190,7 +190,7 @@ func (memR *Reactor) ReceiveEnvelope(e p2p.Envelope) {
|
||||
}
|
||||
|
||||
func (memR *Reactor) Receive(chID byte, peer p2p.Peer, msgBytes []byte) {
|
||||
var msg *protomem.Message
|
||||
msg := &protomem.Message{}
|
||||
err := proto.Unmarshal(msgBytes, msg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
@@ -8,10 +8,12 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-kit/log/term"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/tendermint/tendermint/abci/example/kvstore"
|
||||
"github.com/tendermint/tendermint/p2p/mock"
|
||||
|
||||
cfg "github.com/tendermint/tendermint/config"
|
||||
|
||||
@@ -93,6 +95,35 @@ func TestMempoolVectors(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLegacyReactorReceiveBasic(t *testing.T) {
|
||||
config := cfg.TestConfig()
|
||||
// if there were more than two reactors, the order of transactions could not be
|
||||
// asserted in waitForTxsOnReactors (due to transactions gossiping). If we
|
||||
// replace Connect2Switches (full mesh) with a func, which connects first
|
||||
// reactor to others and nothing else, this test should also pass with >2 reactors.
|
||||
const N = 1
|
||||
reactors := makeAndConnectReactors(config, N)
|
||||
var (
|
||||
reactor = reactors[0]
|
||||
peer = mock.NewPeer(nil)
|
||||
)
|
||||
defer func() {
|
||||
err := reactor.Stop()
|
||||
assert.NoError(t, err)
|
||||
}()
|
||||
|
||||
reactor.InitPeer(peer)
|
||||
reactor.AddPeer(peer)
|
||||
m := &memproto.Txs{}
|
||||
wm := m.Wrap()
|
||||
msg, err := proto.Marshal(wm)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.NotPanics(t, func() {
|
||||
reactor.Receive(mempool.MempoolChannel, peer, msg)
|
||||
})
|
||||
}
|
||||
|
||||
func makeAndConnectReactors(config *cfg.Config, n int) []*Reactor {
|
||||
reactors := make([]*Reactor, n)
|
||||
logger := mempoolLogger()
|
||||
|
||||
Reference in New Issue
Block a user