Browse Source

p2p: fix data race in MakeSwitch test helper (#5810)

Fixes #5809.
pull/5797/head
Erik Grinaker 3 years ago
committed by GitHub
parent
commit
72f041b759
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions
  1. +4
    -4
      p2p/test_util.go
  2. +5
    -0
      p2p/transport_mconn.go

+ 4
- 4
p2p/test_util.go View File

@ -169,15 +169,15 @@ func MakeSwitch(
logger := log.TestingLogger().With("switch", i)
t := NewMConnTransport(logger, nodeInfo, nodeKey.PrivKey, MConnConfig(cfg))
if err := t.Listen(addr.Endpoint()); err != nil {
panic(err)
}
// TODO: let the config be passed in?
sw := initSwitch(i, NewSwitch(cfg, t, opts...))
sw.SetLogger(log.TestingLogger().With("switch", i))
sw.SetNodeKey(nodeKey)
if err := t.Listen(addr.Endpoint()); err != nil {
panic(err)
}
ni := nodeInfo
ni.Channels = []byte{}
for ch := range sw.reactorsByCh {


+ 5
- 0
p2p/transport_mconn.go View File

@ -129,6 +129,11 @@ func NewMConnTransport(
}
// SetChannelDescriptors implements Transport.
//
// This is not concurrency-safe, and must be called before listening.
//
// FIXME: This is here for compatibility with existing switch code,
// it should be passed via the constructor instead.
func (m *MConnTransport) SetChannelDescriptors(chDescs []*conn.ChannelDescriptor) {
m.channelDescs = chDescs
}


Loading…
Cancel
Save