Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-swarm
Commits
ebce7de7
Commit
ebce7de7
authored
Oct 18, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix race conditions in dial_sync and limiter tests
parent
80858d6c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
2 deletions
+9
-2
dial_sync.go
dial_sync.go
+0
-1
limiter_test.go
limiter_test.go
+9
-1
No files found.
dial_sync.go
View file @
ebce7de7
...
...
@@ -81,7 +81,6 @@ func (ds *DialSync) DialLock(ctx context.Context, p peer.ID) (*Conn, error) {
ad
.
conn
,
ad
.
err
=
ds
.
dialFunc
(
ctx
,
p
)
close
(
ad
.
waitch
)
ad
.
cancel
()
ad
.
waitch
=
nil
// to ensure nobody tries reusing this
}(
ctx
,
p
,
actd
)
}
...
...
limiter_test.go
View file @
ebce7de7
...
...
@@ -5,6 +5,7 @@ import (
"fmt"
"math/rand"
"strconv"
"sync"
"testing"
"time"
...
...
@@ -170,13 +171,17 @@ func TestFDLimiting(t *testing.T) {
}
func
TestTokenRedistribution
(
t
*
testing
.
T
)
{
var
lk
sync
.
Mutex
hangchs
:=
make
(
map
[
peer
.
ID
]
chan
struct
{})
df
:=
func
(
ctx
context
.
Context
,
p
peer
.
ID
,
a
ma
.
Multiaddr
)
(
iconn
.
Conn
,
error
)
{
if
tcpPortOver
(
a
,
10
)
{
return
(
iconn
.
Conn
)(
nil
),
nil
}
<-
hangchs
[
p
]
lk
.
Lock
()
ch
:=
hangchs
[
p
]
lk
.
Unlock
()
<-
ch
return
nil
,
fmt
.
Errorf
(
"test bad dial"
)
}
l
:=
newDialLimiterWithParams
(
df
,
8
,
4
)
...
...
@@ -190,6 +195,9 @@ func TestTokenRedistribution(t *testing.T) {
// take all fd limit tokens with hang dials
for
_
,
pid
:=
range
pids
{
hangchs
[
pid
]
=
make
(
chan
struct
{})
}
for
_
,
pid
:=
range
pids
{
tryDialAddrs
(
ctx
,
l
,
pid
,
bads
,
resch
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment