Files
tendermint/internal/p2p/transport_memory_test.go
Sam Kleinman 0bded371c5 testing: logger cleanup (#8153)
This contains two major changes:

- Remove the legacy test logging method, and just explicitly call the
  noop logger. This is just to make the test logging behavior more
  coherent and clear. 
  
- Move the logging in the light package from the testing.T logger to
  the noop logger. It's really the case that we very rarely need/want
  to consider test logs unless we're doing reproductions and running a
  narrow set of tests.
  
In most cases, I (for one) prefer to run in verbose mode so I can
watch progress of tests, but I basically never need to consider
logs. If I do want to see logs, then I can edit in the testing.T
logger locally (which is what you have to do today, anyway.)
2022-03-18 17:39:38 +00:00

37 lines
968 B
Go

package p2p_test
import (
"bytes"
"encoding/hex"
"testing"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/internal/p2p"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/types"
)
// Transports are mainly tested by common tests in transport_test.go, we
// register a transport factory here to get included in those tests.
func init() {
var network *p2p.MemoryNetwork // shared by transports in the same test
testTransports["memory"] = func(t *testing.T) p2p.Transport {
if network == nil {
network = p2p.NewMemoryNetwork(log.NewNopLogger(), 1)
}
i := byte(network.Size())
nodeID, err := types.NewNodeID(hex.EncodeToString(bytes.Repeat([]byte{i<<4 + i}, 20)))
require.NoError(t, err)
transport := network.CreateTransport(nodeID)
t.Cleanup(func() {
require.NoError(t, transport.Close())
network = nil // set up a new memory network for the next test
})
return transport
}
}