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

Commit

Permalink
speed up the TestFDLimitUnderflow test
Browse files Browse the repository at this point in the history
We're setting a limit of 20 fds, so we don't need to test 1000 dials.
  • Loading branch information
marten-seemann committed May 19, 2021
1 parent b80b91c commit 4728fd6
Showing 1 changed file with 9 additions and 24 deletions.
33 changes: 9 additions & 24 deletions limiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,35 +358,31 @@ func TestStressLimiter(t *testing.T) {
}

func TestFDLimitUnderflow(t *testing.T) {
df := func(ctx context.Context, p peer.ID, a ma.Multiaddr) (transport.CapableConn, error) {
timeout := make(chan bool, 1)
go func() {
time.Sleep(time.Second * 5)
timeout <- true
}()

df := func(ctx context.Context, p peer.ID, addr ma.Multiaddr) (transport.CapableConn, error) {
select {
case <-ctx.Done():
case <-timeout:
case <-time.After(5 * time.Second):
}

return nil, fmt.Errorf("df timed out")
}

l := newDialLimiterWithParams(isFdConsuming, df, 20, 3)
const fdLimit = 20
l := newDialLimiterWithParams(isFdConsuming, df, fdLimit, 3)

var addrs []ma.Multiaddr
for i := 0; i <= 1000; i++ {
addrs = append(addrs, addrWithPort(t, i))
}

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

resp := make(chan dialResult)
l.AddDialJob(&dialJob{
Expand All @@ -396,17 +392,6 @@ func TestFDLimitUnderflow(t *testing.T) {
resp: resp,
})

//cancel first 60 after 1s, next 60 after 2s
if i > 60 {
time.Sleep(time.Second * 1)
}
if i < 120 {
time.Sleep(time.Second * 1)
cancel()
return
}
defer cancel()

for res := range resp {
if res.Err != nil {
return
Expand Down

0 comments on commit 4728fd6

Please sign in to comment.