test: fix test data race in p2p.MemoryTransport with logger (#5995)

This patches over a test data race where the logger would try to read struct internals via `reflect` while these were concurrently modified (specifically `MemoryTransport.closeOnce`).
This commit is contained in:
Erik Grinaker
2021-01-27 21:05:48 +00:00
committed by GitHub
parent bd8a9372d2
commit aead4ab555
+10
View File
@@ -135,6 +135,16 @@ func newMemoryTransport(
}
}
// String displays the transport.
//
// FIXME: The Transport interface should either have Name() or embed
// fmt.Stringer. This is necessary since we log the transport (to know which one
// it is), and if it doesn't implement fmt.Stringer then it inspects all struct
// contents via reflect, which triggers the race detector.
func (t *MemoryTransport) String() string {
return "memory"
}
// Accept implements Transport.
func (t *MemoryTransport) Accept(ctx context.Context) (Connection, error) {
select {