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 3 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:
name: crashers
path: test/fuzz/**/crashers
retention-days: 1
retention-days: 3
- name: Archive suppressions
uses: actions/upload-artifact@v2
with:
name: suppressions
path: test/fuzz/**/suppressions
retention-days: 1
retention-days: 3
- name: Set crashers count
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)
return sw
})
}, logger)
}
for _, sw := range switches {
@ -406,7 +406,7 @@ func TestPEXReactorSeedModeFlushStop(t *testing.T) {
sw.AddReactor("pex", r)
return sw
})
}, logger)
}
for _, sw := range switches {
@ -567,6 +567,7 @@ func testCreatePeerWithConfig(dir string, id int, config *ReactorConfig) *p2p.Sw
sw.AddReactor("pex", r)
return sw
},
log.TestingLogger(),
)
return peer
}
@ -600,6 +601,7 @@ func testCreateSeed(dir string, id int, knownAddrs, srcAddrs []*p2p.NetAddress)
sw.AddReactor("pex", r)
return sw
},
log.TestingLogger(),
)
return seed
}
@ -629,8 +631,7 @@ func createSwitchAndAddReactors(reactors ...p2p.Reactor) *p2p.Switch {
sw.AddReactor(r.String(), r)
}
return sw
})
sw.SetLogger(log.TestingLogger())
}, log.TestingLogger())
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)
return sw
})
}, log.TestingLogger())
// start the reactor shim
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) {
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
rp := &remotePeer{PrivKey: s1.nodeKey.PrivKey, Config: cfg}
@ -225,6 +225,7 @@ func TestSwitchPeerFilter(t *testing.T) {
"testing",
"123.123.123",
initSwitchFunc,
log.TestingLogger(),
SwitchPeerFilters(filters...),
)
)
@ -280,6 +281,7 @@ func TestSwitchPeerFilterTimeout(t *testing.T) {
"testing",
"123.123.123",
initSwitchFunc,
log.TestingLogger(),
SwitchFilterTimeout(5*time.Millisecond),
SwitchPeerFilters(filters...),
)
@ -319,7 +321,7 @@ func TestSwitchPeerFilterTimeout(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()
require.NoError(t, err)
t.Cleanup(func() {
@ -372,7 +374,7 @@ func assertNoPeersAfterTimeout(t *testing.T, sw *Switch, timeout time.Duration)
func TestSwitchStopsNonPersistentPeerOnError(t *testing.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()
if err != nil {
t.Error(err)
@ -471,7 +473,7 @@ func TestSwitchStopPeerForError(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()
require.NoError(t, err)
t.Cleanup(func() {
@ -521,7 +523,7 @@ func TestSwitchReconnectsToOutboundPersistentPeer(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()
require.NoError(t, err)
t.Cleanup(func() {
@ -554,7 +556,7 @@ func TestSwitchDialPeersAsync(t *testing.T) {
return
}
sw := MakeSwitch(cfg, 1, "testing", "123.123.123", initSwitchFunc)
sw := MakeSwitch(cfg, 1, "testing", "123.123.123", initSwitchFunc, log.TestingLogger())
err := sw.Start()
require.NoError(t, err)
t.Cleanup(func() {
@ -620,7 +622,7 @@ func TestSwitchAcceptRoutine(t *testing.T) {
}
// 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)
require.NoError(t, err)
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.AddReactor("mock", reactor)
return sw
})
}, log.TestingLogger())
err := sw.Start()
require.NoError(t, err)
t.Cleanup(func() {


+ 5
- 4
p2p/test_util.go View File

@ -71,7 +71,7 @@ func MakeConnectedSwitches(cfg *config.P2PConfig,
) []*Switch {
switches := make([]*Switch, n)
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 {
@ -163,6 +163,7 @@ func MakeSwitch(
i int,
network, version string,
initSwitch func(int, *Switch) *Switch,
logger log.Logger,
opts ...SwitchOption,
) *Switch {
@ -175,13 +176,13 @@ func MakeSwitch(
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{})
// TODO: let the config be passed in?
sw := initSwitch(i, NewSwitch(cfg, t, opts...))
sw.SetLogger(log.TestingLogger().With("switch", i))
sw.SetLogger(swLogger)
sw.SetNodeKey(nodeKey)
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) {
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()
require.NoError(t, err)
t.Cleanup(func() {
@ -48,7 +48,7 @@ func TestUnsafeDialSeeds(t *testing.T) {
func TestUnsafeDialPeers(t *testing.T) {
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{
Addrs: 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 (
"net"
"os"
"github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/crypto/ed25519"
@ -13,8 +14,9 @@ import (
)
var (
pexR *pex.Reactor
peer p2p.Peer
pexR *pex.Reactor
peer p2p.Peer
logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout))
)
func init() {
@ -23,19 +25,22 @@ func init() {
if pexR == nil {
panic("NewReactor returned nil")
}
pexR.SetLogger(log.NewNopLogger())
pexR.SetLogger(logger)
peer := newFuzzPeer()
pexR.AddPeer(peer)
}
func Fuzz(data []byte) int {
if len(data) == 0 {
return -1
}
// MakeSwitch uses log.TestingLogger which can't be executed in init()
cfg := config.DefaultP2PConfig()
cfg.PexReactor = true
sw := p2p.MakeSwitch(cfg, 0, "127.0.0.1", "123.123.123", func(i int, sw *p2p.Switch) *p2p.Switch {
return sw
})
}, logger)
pexR.SetSwitch(sw)
pexR.Receive(pex.PexChannel, peer, data)
@ -64,7 +69,7 @@ var defaultNodeInfo = p2p.NodeInfo{
0,
),
NodeID: nodeID,
ListenAddr: "0.0.0.0:98992",
ListenAddr: "0.0.0.0:8992",
Moniker: "foo1",
}


Loading…
Cancel
Save