Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

fix go vet #253

Merged
merged 3 commits into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions dial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,19 +583,23 @@ func TestDialSimultaneousJoin(t *testing.T) {
go acceptAndHang(s2silentListener)

connch := make(chan network.Conn, 512)
errs := make(chan error, 2)

// start a dial to s2 through the silent addr
go func() {
s1.Peerstore().AddAddrs(s2.LocalPeer(), s2silentAddrs, peerstore.PermanentAddrTTL)

c, err := s1.DialPeer(ctx, s2.LocalPeer())
if err != nil {
t.Fatal(err)
errs <- err
connch <- nil
return
}

t.Logf("first dial succedded; conn: %+v", c)

connch <- c
errs <- nil
}()

// wait a bit for the dial to take hold
Expand All @@ -605,18 +609,22 @@ func TestDialSimultaneousJoin(t *testing.T) {
go func() {
s2addrs, err := s2.InterfaceListenAddresses()
if err != nil {
t.Fatal(err)
errs <- err
return
}
s1.Peerstore().AddAddrs(s2.LocalPeer(), s2addrs[:1], peerstore.PermanentAddrTTL)

c, err := s1.DialPeer(ctx, s2.LocalPeer())
if err != nil {
t.Fatal(err)
errs <- err
connch <- nil
return
}

t.Logf("second dial succedded; conn: %+v", c)

connch <- c
errs <- nil
}()

// wait for the second dial to finish
Expand All @@ -626,16 +634,27 @@ func TestDialSimultaneousJoin(t *testing.T) {
go func() {
c, err := s1.DialPeer(ctx, s2.LocalPeer())
if err != nil {
t.Fatal(err)
errs <- err
connch <- nil
return
}

t.Logf("third dial succedded; conn: %+v", c)

connch <- c
errs <- nil
}()

c3 := <-connch

// raise any errors from the previous goroutines
for i := 0; i < 3; i++ {
err := <-errs
if err != nil {
t.Fatal(err)
}
}

if c2 != c3 {
t.Fatal("expected c2 and c3 to be the same")
}
Expand Down
16 changes: 14 additions & 2 deletions limiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package swarm

import (
"context"
"errors"
"fmt"
"math/rand"
"strconv"
Expand Down Expand Up @@ -379,8 +380,12 @@ func TestFDLimitUnderflow(t *testing.T) {
addrs = append(addrs, addrWithPort(t, i))
}

wg := sync.WaitGroup{}
wg.Add(1000)
errs := make(chan error, 1000)
for i := 0; i < 1000; i++ {
go func(id peer.ID, i int) {
defer wg.Done()
ctx, cancel := context.WithCancel(context.Background())

resp := make(chan dialResult)
Expand All @@ -406,12 +411,19 @@ func TestFDLimitUnderflow(t *testing.T) {
if res.Err != nil {
return
}
t.Fatal("got dial res, shouldn't")
errs <- errors.New("got dial res, but shouldn't")
}
}(peer.ID(fmt.Sprintf("testpeer%d", i%20)), i)
}

time.Sleep(time.Second * 3)
go func() {
wg.Wait()
close(errs)
}()

for err := range errs {
t.Fatal(err)
}

l.lk.Lock()
fdConsuming := l.fdConsuming
Expand Down