fix(net/multiconn) data race in test
https://build.protocol-dev.com/job/go-ipfs.test.go.race.nofuse/276/console License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
Brian Tiger Chow committed
Nov 29, 2014 at 15:41 UTC
229c93f72f7f69f046151b639972f150cde1e69b
2 files changed
+12
-2
net/conn/multiconn.go
+10
@@ -262,6 +262,16 @@ func (c *MultiConn) ID() string {
262
return string(ids)
263
}
264
265
+func (c *MultiConn) Conns() []Conn {
266
+ c.RLock()
267
+ defer c.RUnlock()
268
+ var conns []Conn
269
+ for _, c := range c.conns {
270
+ conns = append(conns, c)
271
+ }
272
+ return conns
273
+}
274
+
275
func (c *MultiConn) String() string {
276
return String(c, "MultiConn")
277
}
net/conn/multiconn_test.go
+2
-2
@@ -307,11 +307,11 @@ func TestMulticonnClose(t *testing.T) {
307
ctx := context.Background()
308
c1, c2 := setupMultiConns(t, ctx)
309
310
- for _, c := range c1.conns {
310
+ for _, c := range c1.Conns() {
311
c.Close()
312
}
313
314
- for _, c := range c2.conns {
314
+ for _, c := range c2.Conns() {
315
c.Close()
316
}
317