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
dms3
go-bitswap
Commits
964888c4
Unverified
Commit
964888c4
authored
Mar 10, 2020
by
dirkmc
Committed by
GitHub
Mar 10, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: flaky provider query manager (#286)
parent
a441107f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
2 deletions
+8
-2
internal/providerquerymanager/providerquerymanager_test.go
internal/providerquerymanager/providerquerymanager_test.go
+8
-2
No files found.
internal/providerquerymanager/providerquerymanager_test.go
View file @
964888c4
...
...
@@ -21,6 +21,7 @@ type fakeProviderNetwork struct {
connectDelay
time
.
Duration
queriesMadeMutex
sync
.
RWMutex
queriesMade
int
liveQueries
int
}
func
(
fpn
*
fakeProviderNetwork
)
ConnectTo
(
context
.
Context
,
peer
.
ID
)
error
{
...
...
@@ -31,6 +32,7 @@ func (fpn *fakeProviderNetwork) ConnectTo(context.Context, peer.ID) error {
func
(
fpn
*
fakeProviderNetwork
)
FindProvidersAsync
(
ctx
context
.
Context
,
k
cid
.
Cid
,
max
int
)
<-
chan
peer
.
ID
{
fpn
.
queriesMadeMutex
.
Lock
()
fpn
.
queriesMade
++
fpn
.
liveQueries
++
fpn
.
queriesMadeMutex
.
Unlock
()
incomingPeers
:=
make
(
chan
peer
.
ID
)
go
func
()
{
...
...
@@ -48,7 +50,11 @@ func (fpn *fakeProviderNetwork) FindProvidersAsync(ctx context.Context, k cid.Ci
return
}
}
fpn
.
queriesMadeMutex
.
Lock
()
fpn
.
liveQueries
--
fpn
.
queriesMadeMutex
.
Unlock
()
}()
return
incomingPeers
}
...
...
@@ -264,8 +270,8 @@ func TestRateLimitingRequests(t *testing.T) {
}
time
.
Sleep
(
9
*
time
.
Millisecond
)
fpn
.
queriesMadeMutex
.
Lock
()
if
fpn
.
q
ueries
Made
!=
maxInProcessRequests
{
t
.
Logf
(
"Queries made: %d
\n
"
,
fpn
.
q
ueries
Made
)
if
fpn
.
liveQ
ueries
!=
maxInProcessRequests
{
t
.
Logf
(
"Queries made: %d
\n
"
,
fpn
.
liveQ
ueries
)
t
.
Fatal
(
"Did not limit parallel requests to rate limit"
)
}
fpn
.
queriesMadeMutex
.
Unlock
()
...
...
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