Skip to content

Commit

Permalink
SubtestPingPong: ensure connections are closed.
Browse files Browse the repository at this point in the history
  • Loading branch information
raulk committed May 23, 2019
1 parent ba0ddf5 commit ce344a8
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions suites/transport/transport_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,21 +169,33 @@ func SubtestPingPong(t *testing.T, ta, tb transport.Transport, maddr ma.Multiadd
}
defer list.Close()

var (
connA, connB transport.CapableConn
)
defer func() {
if connA != nil {
connA.Close()
}
if connB != nil {
connB.Close()
}
}()

var wg sync.WaitGroup

wg.Add(1)
go func() {
defer wg.Done()
c, err := list.Accept()
var err error
connA, err = list.Accept()
if err != nil {
t.Error(err)
return
}
defer c.Close()

var sWg sync.WaitGroup
for i := 0; i < streams; i++ {
s, err := c.AcceptStream()
s, err := connA.AcceptStream()
if err != nil {
t.Error(err)
return
Expand Down Expand Up @@ -225,14 +237,13 @@ func SubtestPingPong(t *testing.T, ta, tb transport.Transport, maddr ma.Multiadd
t.Error("CanDial should have returned true")
}

c, err := tb.Dial(ctx, list.Multiaddr(), peerA)
connB, err = tb.Dial(ctx, list.Multiaddr(), peerA)
if err != nil {
t.Fatal(err)
}
defer c.Close()

for i := 0; i < streams; i++ {
s, err := c.OpenStream()
s, err := connB.OpenStream()
if err != nil {
t.Error(err)
continue
Expand Down

0 comments on commit ce344a8

Please sign in to comment.