Browse Source

test/fuzz: fix PEX reactor test (#6188)

* test/fuzz: fix PEX reactor test

* .github: [fuzz] increase retention period for crashers
pull/6191/head
Anton Kaliaev 4 years ago
committed by GitHub
parent
commit
089b314bdb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 36 additions and 27 deletions
  1. +2
    -2
      .github/workflows/fuzz-nightly.yml
  2. +5
    -4
      p2p/pex/pex_reactor_test.go
  3. +1
    -1
      p2p/shim_test.go
  4. +10
    -8
      p2p/switch_test.go
  5. +5
    -4
      p2p/test_util.go
  6. +2
    -2
      rpc/core/net_test.go
  7. +11
    -6
      test/fuzz/p2p/pex/reactor_receive.go

+ 2
- 2
.github/workflows/fuzz-nightly.yml View File

@ -49,14 +49,14 @@ jobs:
with: with:
name: crashers name: crashers
path: test/fuzz/**/crashers path: test/fuzz/**/crashers
retention-days: 1
retention-days: 3
- name: Archive suppressions - name: Archive suppressions
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
with: with:
name: suppressions name: suppressions
path: test/fuzz/**/suppressions path: test/fuzz/**/suppressions
retention-days: 1
retention-days: 3
- name: Set crashers count - name: Set crashers count
working-directory: test/fuzz working-directory: test/fuzz


+ 5
- 4
p2p/pex/pex_reactor_test.go View File

@ -91,7 +91,7 @@ func TestPEXReactorRunning(t *testing.T) {
sw.AddReactor("pex", r) sw.AddReactor("pex", r)
return sw return sw
})
}, logger)
} }
for _, sw := range switches { for _, sw := range switches {
@ -406,7 +406,7 @@ func TestPEXReactorSeedModeFlushStop(t *testing.T) {
sw.AddReactor("pex", r) sw.AddReactor("pex", r)
return sw return sw
})
}, logger)
} }
for _, sw := range switches { for _, sw := range switches {
@ -567,6 +567,7 @@ func testCreatePeerWithConfig(dir string, id int, config *ReactorConfig) *p2p.Sw
sw.AddReactor("pex", r) sw.AddReactor("pex", r)
return sw return sw
}, },
log.TestingLogger(),
) )
return peer return peer
} }
@ -600,6 +601,7 @@ func testCreateSeed(dir string, id int, knownAddrs, srcAddrs []*p2p.NetAddress)
sw.AddReactor("pex", r) sw.AddReactor("pex", r)
return sw return sw
}, },
log.TestingLogger(),
) )
return seed return seed
} }
@ -629,8 +631,7 @@ func createSwitchAndAddReactors(reactors ...p2p.Reactor) *p2p.Switch {
sw.AddReactor(r.String(), r) sw.AddReactor(r.String(), r)
} }
return sw return sw
})
sw.SetLogger(log.TestingLogger())
}, log.TestingLogger())
return sw return sw
} }


+ 1
- 1
p2p/shim_test.go View File

@ -61,7 +61,7 @@ func setup(t *testing.T, peers []p2p.Peer) *reactorShimTestSuite {
sw.AddReactor(rts.shim.Name, rts.shim) sw.AddReactor(rts.shim.Name, rts.shim)
return sw return sw
})
}, log.TestingLogger())
// start the reactor shim // start the reactor shim
require.NoError(t, rts.shim.Start()) require.NoError(t, rts.shim.Start())


+ 10
- 8
p2p/switch_test.go View File

@ -186,7 +186,7 @@ func assertMsgReceivedWithTimeout(
} }
func TestSwitchFiltersOutItself(t *testing.T) { func TestSwitchFiltersOutItself(t *testing.T) {
s1 := MakeSwitch(cfg, 1, "127.0.0.1", "123.123.123", initSwitchFunc)
s1 := MakeSwitch(cfg, 1, "127.0.0.1", "123.123.123", initSwitchFunc, log.TestingLogger())
// simulate s1 having a public IP by creating a remote peer with the same ID // simulate s1 having a public IP by creating a remote peer with the same ID
rp := &remotePeer{PrivKey: s1.nodeKey.PrivKey, Config: cfg} rp := &remotePeer{PrivKey: s1.nodeKey.PrivKey, Config: cfg}
@ -225,6 +225,7 @@ func TestSwitchPeerFilter(t *testing.T) {
"testing", "testing",
"123.123.123", "123.123.123",
initSwitchFunc, initSwitchFunc,
log.TestingLogger(),
SwitchPeerFilters(filters...), SwitchPeerFilters(filters...),
) )
) )
@ -280,6 +281,7 @@ func TestSwitchPeerFilterTimeout(t *testing.T) {
"testing", "testing",
"123.123.123", "123.123.123",
initSwitchFunc, initSwitchFunc,
log.TestingLogger(),
SwitchFilterTimeout(5*time.Millisecond), SwitchFilterTimeout(5*time.Millisecond),
SwitchPeerFilters(filters...), SwitchPeerFilters(filters...),
) )
@ -319,7 +321,7 @@ func TestSwitchPeerFilterTimeout(t *testing.T) {
} }
func TestSwitchPeerFilterDuplicate(t *testing.T) { func TestSwitchPeerFilterDuplicate(t *testing.T) {
sw := MakeSwitch(cfg, 1, "testing", "123.123.123", initSwitchFunc)
sw := MakeSwitch(cfg, 1, "testing", "123.123.123", initSwitchFunc, log.TestingLogger())
err := sw.Start() err := sw.Start()
require.NoError(t, err) require.NoError(t, err)
t.Cleanup(func() { t.Cleanup(func() {
@ -372,7 +374,7 @@ func assertNoPeersAfterTimeout(t *testing.T, sw *Switch, timeout time.Duration)
func TestSwitchStopsNonPersistentPeerOnError(t *testing.T) { func TestSwitchStopsNonPersistentPeerOnError(t *testing.T) {
assert, require := assert.New(t), require.New(t) assert, require := assert.New(t), require.New(t)
sw := MakeSwitch(cfg, 1, "testing", "123.123.123", initSwitchFunc)
sw := MakeSwitch(cfg, 1, "testing", "123.123.123", initSwitchFunc, log.TestingLogger())
err := sw.Start() err := sw.Start()
if err != nil { if err != nil {
t.Error(err) t.Error(err)
@ -471,7 +473,7 @@ func TestSwitchStopPeerForError(t *testing.T) {
} }
func TestSwitchReconnectsToOutboundPersistentPeer(t *testing.T) { func TestSwitchReconnectsToOutboundPersistentPeer(t *testing.T) {
sw := MakeSwitch(cfg, 1, "testing", "123.123.123", initSwitchFunc)
sw := MakeSwitch(cfg, 1, "testing", "123.123.123", initSwitchFunc, log.TestingLogger())
err := sw.Start() err := sw.Start()
require.NoError(t, err) require.NoError(t, err)
t.Cleanup(func() { t.Cleanup(func() {
@ -521,7 +523,7 @@ func TestSwitchReconnectsToOutboundPersistentPeer(t *testing.T) {
} }
func TestSwitchReconnectsToInboundPersistentPeer(t *testing.T) { func TestSwitchReconnectsToInboundPersistentPeer(t *testing.T) {
sw := MakeSwitch(cfg, 1, "testing", "123.123.123", initSwitchFunc)
sw := MakeSwitch(cfg, 1, "testing", "123.123.123", initSwitchFunc, log.TestingLogger())
err := sw.Start() err := sw.Start()
require.NoError(t, err) require.NoError(t, err)
t.Cleanup(func() { t.Cleanup(func() {
@ -554,7 +556,7 @@ func TestSwitchDialPeersAsync(t *testing.T) {
return return
} }
sw := MakeSwitch(cfg, 1, "testing", "123.123.123", initSwitchFunc)
sw := MakeSwitch(cfg, 1, "testing", "123.123.123", initSwitchFunc, log.TestingLogger())
err := sw.Start() err := sw.Start()
require.NoError(t, err) require.NoError(t, err)
t.Cleanup(func() { t.Cleanup(func() {
@ -620,7 +622,7 @@ func TestSwitchAcceptRoutine(t *testing.T) {
} }
// make switch // make switch
sw := MakeSwitch(cfg, 1, "testing", "123.123.123", initSwitchFunc)
sw := MakeSwitch(cfg, 1, "testing", "123.123.123", initSwitchFunc, log.TestingLogger())
err := sw.AddUnconditionalPeerIDs(unconditionalPeerIDs) err := sw.AddUnconditionalPeerIDs(unconditionalPeerIDs)
require.NoError(t, err) require.NoError(t, err)
err = sw.Start() err = sw.Start()
@ -785,7 +787,7 @@ func TestSwitchInitPeerIsNotCalledBeforeRemovePeer(t *testing.T) {
sw := MakeSwitch(cfg, 1, "testing", "123.123.123", func(i int, sw *Switch) *Switch { sw := MakeSwitch(cfg, 1, "testing", "123.123.123", func(i int, sw *Switch) *Switch {
sw.AddReactor("mock", reactor) sw.AddReactor("mock", reactor)
return sw return sw
})
}, log.TestingLogger())
err := sw.Start() err := sw.Start()
require.NoError(t, err) require.NoError(t, err)
t.Cleanup(func() { t.Cleanup(func() {


+ 5
- 4
p2p/test_util.go View File

@ -71,7 +71,7 @@ func MakeConnectedSwitches(cfg *config.P2PConfig,
) []*Switch { ) []*Switch {
switches := make([]*Switch, n) switches := make([]*Switch, n)
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
switches[i] = MakeSwitch(cfg, i, TestHost, "123.123.123", initSwitch)
switches[i] = MakeSwitch(cfg, i, TestHost, "123.123.123", initSwitch, log.TestingLogger())
} }
if err := StartSwitches(switches); err != nil { if err := StartSwitches(switches); err != nil {
@ -163,6 +163,7 @@ func MakeSwitch(
i int, i int,
network, version string, network, version string,
initSwitch func(int, *Switch) *Switch, initSwitch func(int, *Switch) *Switch,
logger log.Logger,
opts ...SwitchOption, opts ...SwitchOption,
) *Switch { ) *Switch {
@ -175,13 +176,13 @@ func MakeSwitch(
panic(err) panic(err)
} }
logger := log.TestingLogger().With("switch", i)
t := NewMConnTransport(logger, MConnConfig(cfg),
swLogger := logger.With("switch", i)
t := NewMConnTransport(swLogger, MConnConfig(cfg),
[]*ChannelDescriptor{}, MConnTransportOptions{}) []*ChannelDescriptor{}, MConnTransportOptions{})
// TODO: let the config be passed in? // TODO: let the config be passed in?
sw := initSwitch(i, NewSwitch(cfg, t, opts...)) sw := initSwitch(i, NewSwitch(cfg, t, opts...))
sw.SetLogger(log.TestingLogger().With("switch", i))
sw.SetLogger(swLogger)
sw.SetNodeKey(nodeKey) sw.SetNodeKey(nodeKey)
if err := t.Listen(addr.Endpoint()); err != nil { if err := t.Listen(addr.Endpoint()); err != nil {


+ 2
- 2
rpc/core/net_test.go View File

@ -14,7 +14,7 @@ import (
func TestUnsafeDialSeeds(t *testing.T) { func TestUnsafeDialSeeds(t *testing.T) {
sw := p2p.MakeSwitch(cfg.DefaultP2PConfig(), 1, "testing", "123.123.123", sw := p2p.MakeSwitch(cfg.DefaultP2PConfig(), 1, "testing", "123.123.123",
func(n int, sw *p2p.Switch) *p2p.Switch { return sw })
func(n int, sw *p2p.Switch) *p2p.Switch { return sw }, log.TestingLogger())
err := sw.Start() err := sw.Start()
require.NoError(t, err) require.NoError(t, err)
t.Cleanup(func() { t.Cleanup(func() {
@ -48,7 +48,7 @@ func TestUnsafeDialSeeds(t *testing.T) {
func TestUnsafeDialPeers(t *testing.T) { func TestUnsafeDialPeers(t *testing.T) {
sw := p2p.MakeSwitch(cfg.DefaultP2PConfig(), 1, "testing", "123.123.123", sw := p2p.MakeSwitch(cfg.DefaultP2PConfig(), 1, "testing", "123.123.123",
func(n int, sw *p2p.Switch) *p2p.Switch { return sw })
func(n int, sw *p2p.Switch) *p2p.Switch { return sw }, log.TestingLogger())
sw.SetAddrBook(&p2p.AddrBookMock{ sw.SetAddrBook(&p2p.AddrBookMock{
Addrs: make(map[string]struct{}), Addrs: make(map[string]struct{}),
OurAddrs: make(map[string]struct{}), OurAddrs: make(map[string]struct{}),


+ 11
- 6
test/fuzz/p2p/pex/reactor_receive.go View File

@ -2,6 +2,7 @@ package pex
import ( import (
"net" "net"
"os"
"github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/crypto/ed25519"
@ -13,8 +14,9 @@ import (
) )
var ( var (
pexR *pex.Reactor
peer p2p.Peer
pexR *pex.Reactor
peer p2p.Peer
logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout))
) )
func init() { func init() {
@ -23,19 +25,22 @@ func init() {
if pexR == nil { if pexR == nil {
panic("NewReactor returned nil") panic("NewReactor returned nil")
} }
pexR.SetLogger(log.NewNopLogger())
pexR.SetLogger(logger)
peer := newFuzzPeer() peer := newFuzzPeer()
pexR.AddPeer(peer) pexR.AddPeer(peer)
} }
func Fuzz(data []byte) int { func Fuzz(data []byte) int {
if len(data) == 0 {
return -1
}
// MakeSwitch uses log.TestingLogger which can't be executed in init() // MakeSwitch uses log.TestingLogger which can't be executed in init()
cfg := config.DefaultP2PConfig() cfg := config.DefaultP2PConfig()
cfg.PexReactor = true cfg.PexReactor = true
sw := p2p.MakeSwitch(cfg, 0, "127.0.0.1", "123.123.123", func(i int, sw *p2p.Switch) *p2p.Switch { sw := p2p.MakeSwitch(cfg, 0, "127.0.0.1", "123.123.123", func(i int, sw *p2p.Switch) *p2p.Switch {
return sw return sw
})
}, logger)
pexR.SetSwitch(sw) pexR.SetSwitch(sw)
pexR.Receive(pex.PexChannel, peer, data) pexR.Receive(pex.PexChannel, peer, data)
@ -64,7 +69,7 @@ var defaultNodeInfo = p2p.NodeInfo{
0, 0,
), ),
NodeID: nodeID, NodeID: nodeID,
ListenAddr: "0.0.0.0:98992",
ListenAddr: "0.0.0.0:8992",
Moniker: "foo1", Moniker: "foo1",
} }


Loading…
Cancel
Save