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
ae275396
Commit
ae275396
authored
Aug 20, 2019
by
Dirk McCormick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: session peer manager ordering test timing
parent
a41460dc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
9 deletions
+13
-9
sessionpeermanager/sessionpeermanager_test.go
sessionpeermanager/sessionpeermanager_test.go
+13
-9
No files found.
sessionpeermanager/sessionpeermanager_test.go
View file @
ae275396
...
...
@@ -177,22 +177,24 @@ func TestOrderingPeers(t *testing.T) {
peer1
:=
peers
[
randi
[
0
]]
peer2
:=
peers
[
randi
[
1
]]
peer3
:=
peers
[
randi
[
2
]]
time
.
Sleep
(
10
*
time
.
Millisecond
)
time
.
Sleep
(
5
*
time
.
Millisecond
)
sessionPeerManager
.
RecordPeerResponse
(
peer1
,
[]
cid
.
Cid
{
c
[
0
]})
time
.
Sleep
(
5
0
*
time
.
Millisecond
)
time
.
Sleep
(
2
5
*
time
.
Millisecond
)
sessionPeerManager
.
RecordPeerResponse
(
peer2
,
[]
cid
.
Cid
{
c
[
0
]})
time
.
Sleep
(
10
*
time
.
Millisecond
)
time
.
Sleep
(
5
*
time
.
Millisecond
)
sessionPeerManager
.
RecordPeerResponse
(
peer3
,
[]
cid
.
Cid
{
c
[
0
]})
time
.
Sleep
(
5
*
time
.
Millisecond
)
sessionPeers
:=
sessionPeerManager
.
GetOptimizedPeers
()
if
len
(
sessionPeers
)
!=
maxOptimizedPeers
{
t
.
Fatal
(
fmt
.
Sprintf
(
"Should not return more (%d) than the max of optimized peers (%d)"
,
len
(
sessionPeers
),
maxOptimizedPeers
))
}
// should prioritize peers which are fastest
// peer1: ~
10
ms
// peer2:
10
+ 5
0
= ~
6
0ms
// peer3:
10
+ 5
0
+
10
= ~
70
ms
// peer1: ~
5
ms
// peer2:
5
+
2
5 = ~
3
0ms
// peer3:
5
+
2
5 +
5
= ~
35
ms
if
(
sessionPeers
[
0
]
.
Peer
!=
peer1
)
||
(
sessionPeers
[
1
]
.
Peer
!=
peer2
)
||
(
sessionPeers
[
2
]
.
Peer
!=
peer3
)
{
t
.
Fatal
(
"Did not prioritize peers that received blocks"
)
}
...
...
@@ -223,6 +225,8 @@ func TestOrderingPeers(t *testing.T) {
// Receive a second time
sessionPeerManager
.
RecordPeerResponse
(
peer3
,
[]
cid
.
Cid
{
c2
[
0
]})
time
.
Sleep
(
5
*
time
.
Millisecond
)
// call again
nextSessionPeers
:=
sessionPeerManager
.
GetOptimizedPeers
()
if
len
(
nextSessionPeers
)
!=
maxOptimizedPeers
{
...
...
@@ -230,9 +234,9 @@ func TestOrderingPeers(t *testing.T) {
}
// should sort by average latency
// peer1: ~
10
ms
// peer3: (~
70
ms + ~
0
ms) / 2 = ~3
5
ms
// peer2: ~
6
0ms
// peer1: ~
5
ms
// peer3: (~
35ms + ~5
ms + ~
5
ms) / 2 = ~
2
3ms
// peer2: ~
3
0ms
if
(
nextSessionPeers
[
0
]
.
Peer
!=
peer1
)
||
(
nextSessionPeers
[
1
]
.
Peer
!=
peer3
)
||
(
nextSessionPeers
[
2
]
.
Peer
!=
peer2
)
{
t
.
Fatal
(
"Did not correctly update order of peers sorted by average latency"
)
...
...
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