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
1f09ef51
Commit
1f09ef51
authored
Sep 06, 2019
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
engine(test): test peer usefulness tagging
parent
cdc87be0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
0 deletions
+40
-0
decision/engine_test.go
decision/engine_test.go
+40
-0
No files found.
decision/engine_test.go
View file @
1f09ef51
...
@@ -276,6 +276,46 @@ func TestTaggingPeers(t *testing.T) {
...
@@ -276,6 +276,46 @@ func TestTaggingPeers(t *testing.T) {
t
.
Fatal
(
"Peers should be untagged but weren't"
)
t
.
Fatal
(
"Peers should be untagged but weren't"
)
}
}
}
}
func
TestTaggingUseful
(
t
*
testing
.
T
)
{
oldShortTerm
:=
shortTerm
shortTerm
=
1
*
time
.
Millisecond
defer
func
()
{
shortTerm
=
oldShortTerm
}()
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
1
*
time
.
Second
)
defer
cancel
()
me
:=
newEngine
(
ctx
,
"engine"
)
friend
:=
peer
.
ID
(
"friend"
)
block
:=
blocks
.
NewBlock
([]
byte
(
"foobar"
))
msg
:=
message
.
New
(
false
)
msg
.
AddBlock
(
block
)
for
i
:=
0
;
i
<
3
;
i
++
{
if
me
.
PeerTagger
.
count
(
me
.
Engine
.
tagUseful
)
!=
0
{
t
.
Fatal
(
"Peers should be untagged but weren't"
)
}
me
.
Engine
.
MessageSent
(
friend
,
msg
)
time
.
Sleep
(
shortTerm
*
2
)
if
me
.
PeerTagger
.
count
(
me
.
Engine
.
tagUseful
)
!=
1
{
t
.
Fatal
(
"Peers should be tagged but weren't"
)
}
time
.
Sleep
(
shortTerm
*
8
)
}
if
me
.
PeerTagger
.
count
(
me
.
Engine
.
tagUseful
)
==
0
{
t
.
Fatal
(
"peers should still be tagged due to long-term usefulness"
)
}
time
.
Sleep
(
shortTerm
*
2
)
if
me
.
PeerTagger
.
count
(
me
.
Engine
.
tagUseful
)
==
0
{
t
.
Fatal
(
"peers should still be tagged due to long-term usefulness"
)
}
time
.
Sleep
(
shortTerm
*
10
)
if
me
.
PeerTagger
.
count
(
me
.
Engine
.
tagUseful
)
!=
0
{
t
.
Fatal
(
"peers should finally be untagged"
)
}
}
func
partnerWants
(
e
*
Engine
,
keys
[]
string
,
partner
peer
.
ID
)
{
func
partnerWants
(
e
*
Engine
,
keys
[]
string
,
partner
peer
.
ID
)
{
add
:=
message
.
New
(
false
)
add
:=
message
.
New
(
false
)
for
i
,
letter
:=
range
keys
{
for
i
,
letter
:=
range
keys
{
...
...
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