add allocate in Receive calls (#9667)

This commit is contained in:
William Banfield
2022-11-04 14:04:35 -04:00
committed by GitHub
parent 7417ddf351
commit e7b9ee7cef
20 changed files with 231 additions and 12 deletions
+1 -1
View File
@@ -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)
+26
View File
@@ -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 {
+1 -1
View File
@@ -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)
+31
View File
@@ -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()