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
02942c30
Commit
02942c30
authored
Apr 23, 2020
by
Dirk McCormick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: race in session test
parent
932e2d60
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
2 deletions
+11
-2
internal/session/session_test.go
internal/session/session_test.go
+11
-2
No files found.
internal/session/session_test.go
View file @
02942c30
...
...
@@ -2,6 +2,7 @@ package session
import
(
"context"
"sync"
"testing"
"time"
...
...
@@ -59,8 +60,9 @@ type wantReq struct {
}
type
fakePeerManager
struct
{
cancels
[]
cid
.
Cid
wantReqs
chan
wantReq
lk
sync
.
Mutex
cancels
[]
cid
.
Cid
}
func
newFakePeerManager
()
*
fakePeerManager
{
...
...
@@ -81,8 +83,15 @@ func (pm *fakePeerManager) BroadcastWantHaves(ctx context.Context, cids []cid.Ci
}
}
func
(
pm
*
fakePeerManager
)
SendCancels
(
ctx
context
.
Context
,
cancels
[]
cid
.
Cid
)
{
pm
.
lk
.
Lock
()
defer
pm
.
lk
.
Unlock
()
pm
.
cancels
=
append
(
pm
.
cancels
,
cancels
...
)
}
func
(
pm
*
fakePeerManager
)
allCancels
()
[]
cid
.
Cid
{
pm
.
lk
.
Lock
()
defer
pm
.
lk
.
Unlock
()
return
append
([]
cid
.
Cid
{},
pm
.
cancels
...
)
}
func
TestSessionGetBlocks
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
100
*
time
.
Millisecond
)
...
...
@@ -173,7 +182,7 @@ func TestSessionGetBlocks(t *testing.T) {
time
.
Sleep
(
10
*
time
.
Millisecond
)
// Verify wants were cancelled
if
len
(
fpm
.
c
ancels
)
!=
len
(
blks
)
{
if
len
(
fpm
.
allC
ancels
()
)
!=
len
(
blks
)
{
t
.
Fatal
(
"expected cancels to be sent for all wants"
)
}
}
...
...
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