Unverified Commit 827488e2 authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #253 from coryschwartz/feat/fix-go-vet

fix go vet
parents 68ae307f efeb82bf
......@@ -583,6 +583,7 @@ 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() {
......@@ -590,12 +591,15 @@ func TestDialSimultaneousJoin(t *testing.T) {
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
......@@ -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
......@@ -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")
}
......
......@@ -2,6 +2,7 @@ package swarm
import (
"context"
"errors"
"fmt"
"math/rand"
"strconv"
......@@ -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)
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment