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
04e47665
Commit
04e47665
authored
Feb 26, 2019
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test(prq): test canceling FindProviders context after completion
parent
21ccf0c7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
0 deletions
+32
-0
providerquerymanager/providerquerymanager_test.go
providerquerymanager/providerquerymanager_test.go
+32
-0
No files found.
providerquerymanager/providerquerymanager_test.go
View file @
04e47665
...
...
@@ -329,3 +329,35 @@ func TestFindProviderPreCanceled(t *testing.T) {
t
.
Fatal
(
"shouldn't have blocked waiting on a closed context"
)
}
}
func
TestCancelFindProvidersAfterCompletion
(
t
*
testing
.
T
)
{
peers
:=
testutil
.
GeneratePeers
(
2
)
fpn
:=
&
fakeProviderNetwork
{
peersFound
:
peers
,
delay
:
1
*
time
.
Millisecond
,
}
ctx
:=
context
.
Background
()
providerQueryManager
:=
New
(
ctx
,
fpn
)
providerQueryManager
.
Startup
()
providerQueryManager
.
SetFindProviderTimeout
(
100
*
time
.
Millisecond
)
keys
:=
testutil
.
GenerateCids
(
1
)
sessionCtx
,
cancel
:=
context
.
WithCancel
(
ctx
)
firstRequestChan
:=
providerQueryManager
.
FindProvidersAsync
(
sessionCtx
,
keys
[
0
])
<-
firstRequestChan
// wait for everything to start.
time
.
Sleep
(
10
*
time
.
Millisecond
)
// wait for the incoming providres to stop.
cancel
()
// cancel the context.
timer
:=
time
.
NewTimer
(
10
*
time
.
Millisecond
)
defer
timer
.
Stop
()
for
{
select
{
case
_
,
ok
:=
<-
firstRequestChan
:
if
!
ok
{
return
}
case
<-
timer
.
C
:
t
.
Fatal
(
"should have finished receiving responses within timeout"
)
}
}
}
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