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
916de59d
Unverified
Commit
916de59d
authored
Dec 18, 2018
by
Hannah Howard
Committed by
GitHub
Dec 18, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #44 from ipfs/bugs/stabilize-test-suite
fix(tests): stabilize unreliable session tests
parents
f1fb3da1
6b3042fe
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
15 deletions
+15
-15
session/session_test.go
session/session_test.go
+5
-14
sessionpeermanager/sessionpeermanager_test.go
sessionpeermanager/sessionpeermanager_test.go
+10
-1
No files found.
session/session_test.go
View file @
916de59d
...
@@ -35,13 +35,11 @@ func (fwm *fakeWantManager) CancelWants(ctx context.Context, cids []cid.Cid, pee
...
@@ -35,13 +35,11 @@ func (fwm *fakeWantManager) CancelWants(ctx context.Context, cids []cid.Cid, pee
type
fakePeerManager
struct
{
type
fakePeerManager
struct
{
lk
sync
.
RWMutex
lk
sync
.
RWMutex
peers
[]
peer
.
ID
peers
[]
peer
.
ID
findMorePeersRequested
bool
findMorePeersRequested
chan
struct
{}
}
}
func
(
fpm
*
fakePeerManager
)
FindMorePeers
(
context
.
Context
,
cid
.
Cid
)
{
func
(
fpm
*
fakePeerManager
)
FindMorePeers
(
context
.
Context
,
cid
.
Cid
)
{
fpm
.
lk
.
Lock
()
fpm
.
findMorePeersRequested
<-
struct
{}{}
fpm
.
findMorePeersRequested
=
true
fpm
.
lk
.
Unlock
()
}
}
func
(
fpm
*
fakePeerManager
)
GetOptimizedPeers
()
[]
peer
.
ID
{
func
(
fpm
*
fakePeerManager
)
GetOptimizedPeers
()
[]
peer
.
ID
{
...
@@ -161,7 +159,7 @@ func TestSessionFindMorePeers(t *testing.T) {
...
@@ -161,7 +159,7 @@ func TestSessionFindMorePeers(t *testing.T) {
wantReqs
:=
make
(
chan
wantReq
,
1
)
wantReqs
:=
make
(
chan
wantReq
,
1
)
cancelReqs
:=
make
(
chan
wantReq
,
1
)
cancelReqs
:=
make
(
chan
wantReq
,
1
)
fwm
:=
&
fakeWantManager
{
wantReqs
,
cancelReqs
}
fwm
:=
&
fakeWantManager
{
wantReqs
,
cancelReqs
}
fpm
:=
&
fakePeerManager
{}
fpm
:=
&
fakePeerManager
{
findMorePeersRequested
:
make
(
chan
struct
{})
}
id
:=
testutil
.
GenerateSessionID
()
id
:=
testutil
.
GenerateSessionID
()
session
:=
New
(
ctx
,
id
,
fwm
,
fpm
)
session
:=
New
(
ctx
,
id
,
fwm
,
fpm
)
session
.
SetBaseTickDelay
(
200
*
time
.
Microsecond
)
session
.
SetBaseTickDelay
(
200
*
time
.
Microsecond
)
...
@@ -187,15 +185,8 @@ func TestSessionFindMorePeers(t *testing.T) {
...
@@ -187,15 +185,8 @@ func TestSessionFindMorePeers(t *testing.T) {
<-
wantReqs
<-
wantReqs
<-
cancelReqs
<-
cancelReqs
// wait long enough for a tick to occur
// wait for a request to get more peers to occur
time
.
Sleep
(
20
*
time
.
Millisecond
)
<-
fpm
.
findMorePeersRequested
// trigger to find providers should have happened
fpm
.
lk
.
Lock
()
if
fpm
.
findMorePeersRequested
!=
true
{
t
.
Fatal
(
"should have attempted to find more peers but didn't"
)
}
fpm
.
lk
.
Unlock
()
// verify a broadcast was made
// verify a broadcast was made
receivedWantReq
:=
<-
wantReqs
receivedWantReq
:=
<-
wantReqs
...
...
sessionpeermanager/sessionpeermanager_test.go
View file @
916de59d
...
@@ -2,6 +2,7 @@ package sessionpeermanager
...
@@ -2,6 +2,7 @@ package sessionpeermanager
import
(
import
(
"context"
"context"
"sync"
"testing"
"testing"
"time"
"time"
...
@@ -39,12 +40,17 @@ func (fpn *fakePeerNetwork) FindProvidersAsync(ctx context.Context, c cid.Cid, n
...
@@ -39,12 +40,17 @@ func (fpn *fakePeerNetwork) FindProvidersAsync(ctx context.Context, c cid.Cid, n
type
fakeConnManager
struct
{
type
fakeConnManager
struct
{
taggedPeers
[]
peer
.
ID
taggedPeers
[]
peer
.
ID
wait
sync
.
WaitGroup
}
}
func
(
fcm
*
fakeConnManager
)
TagPeer
(
p
peer
.
ID
,
tag
string
,
n
int
)
{
func
(
fcm
*
fakeConnManager
)
TagPeer
(
p
peer
.
ID
,
tag
string
,
n
int
)
{
fcm
.
wait
.
Add
(
1
)
fcm
.
taggedPeers
=
append
(
fcm
.
taggedPeers
,
p
)
fcm
.
taggedPeers
=
append
(
fcm
.
taggedPeers
,
p
)
}
}
func
(
fcm
*
fakeConnManager
)
UntagPeer
(
p
peer
.
ID
,
tag
string
)
{
func
(
fcm
*
fakeConnManager
)
UntagPeer
(
p
peer
.
ID
,
tag
string
)
{
defer
fcm
.
wait
.
Done
()
for
i
:=
0
;
i
<
len
(
fcm
.
taggedPeers
);
i
++
{
for
i
:=
0
;
i
<
len
(
fcm
.
taggedPeers
);
i
++
{
if
fcm
.
taggedPeers
[
i
]
==
p
{
if
fcm
.
taggedPeers
[
i
]
==
p
{
fcm
.
taggedPeers
[
i
]
=
fcm
.
taggedPeers
[
len
(
fcm
.
taggedPeers
)
-
1
]
fcm
.
taggedPeers
[
i
]
=
fcm
.
taggedPeers
[
len
(
fcm
.
taggedPeers
)
-
1
]
...
@@ -52,7 +58,9 @@ func (fcm *fakeConnManager) UntagPeer(p peer.ID, tag string) {
...
@@ -52,7 +58,9 @@ func (fcm *fakeConnManager) UntagPeer(p peer.ID, tag string) {
return
return
}
}
}
}
}
}
func
(
*
fakeConnManager
)
GetTagInfo
(
p
peer
.
ID
)
*
ifconnmgr
.
TagInfo
{
return
nil
}
func
(
*
fakeConnManager
)
GetTagInfo
(
p
peer
.
ID
)
*
ifconnmgr
.
TagInfo
{
return
nil
}
func
(
*
fakeConnManager
)
TrimOpenConns
(
ctx
context
.
Context
)
{}
func
(
*
fakeConnManager
)
TrimOpenConns
(
ctx
context
.
Context
)
{}
func
(
*
fakeConnManager
)
Notifee
()
inet
.
Notifiee
{
return
nil
}
func
(
*
fakeConnManager
)
Notifee
()
inet
.
Notifiee
{
return
nil
}
...
@@ -130,7 +138,8 @@ func TestUntaggingPeers(t *testing.T) {
...
@@ -130,7 +138,8 @@ func TestUntaggingPeers(t *testing.T) {
t
.
Fatal
(
"Peers were not tagged!"
)
t
.
Fatal
(
"Peers were not tagged!"
)
}
}
<-
ctx
.
Done
()
<-
ctx
.
Done
()
time
.
Sleep
(
5
*
time
.
Millisecond
)
fcm
.
wait
.
Wait
()
if
len
(
fcm
.
taggedPeers
)
!=
0
{
if
len
(
fcm
.
taggedPeers
)
!=
0
{
t
.
Fatal
(
"Peers were not untagged!"
)
t
.
Fatal
(
"Peers were not untagged!"
)
}
}
...
...
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