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-dms3
Commits
b806270e
Commit
b806270e
authored
Sep 21, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test(bitswap) test sending wantlist to peers
parent
b4ef99bc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
3 deletions
+51
-3
exchange/bitswap/bitswap_test.go
exchange/bitswap/bitswap_test.go
+51
-3
No files found.
exchange/bitswap/bitswap_test.go
View file @
b806270e
...
...
@@ -146,10 +146,58 @@ func getOrFail(bitswap instance, b *blocks.Block, t *testing.T, wg *sync.WaitGro
}
func
TestSendToWantingPeer
(
t
*
testing
.
T
)
{
t
.
Log
(
"I get a file from peer |w|. In this message, I receive |w|'s wants"
)
t
.
Log
(
"Peer |w| tells me it wants file |f|, but I don't have it"
)
t
.
Log
(
"Later, peer |o| sends |f| to me"
)
net
:=
tn
.
VirtualNetwork
()
rs
:=
tn
.
VirtualRoutingServer
()
sg
:=
NewSessionGenerator
(
net
,
rs
)
bg
:=
NewBlockGenerator
(
t
)
me
:=
sg
.
Next
()
w
:=
sg
.
Next
()
o
:=
sg
.
Next
()
alpha
:=
bg
.
Next
()
const
timeout
=
100
*
time
.
Millisecond
const
wait
=
100
*
time
.
Millisecond
t
.
Log
(
"Peer |w| attempts to get a file |alpha|. NB: alpha not available"
)
ctx
,
_
:=
context
.
WithTimeout
(
context
.
Background
(),
timeout
)
_
,
err
:=
w
.
exchange
.
Block
(
ctx
,
alpha
.
Key
())
if
err
==
nil
{
t
.
Error
(
"Expected alpha to NOT be available"
)
}
time
.
Sleep
(
wait
)
t
.
Log
(
"Peer |w| announces availability of a file |beta|"
)
beta
:=
bg
.
Next
()
ctx
,
_
=
context
.
WithTimeout
(
context
.
Background
(),
timeout
)
w
.
exchange
.
HasBlock
(
ctx
,
beta
)
time
.
Sleep
(
wait
)
t
.
Log
(
"I request and get |beta| from |w|. In the message, I receive |w|'s wants [alpha]"
)
t
.
Log
(
"I don't have alpha, but I keep it on my wantlist."
)
ctx
,
_
=
context
.
WithTimeout
(
context
.
Background
(),
timeout
)
me
.
exchange
.
Block
(
ctx
,
beta
.
Key
())
time
.
Sleep
(
wait
)
t
.
Log
(
"Peer |o| announces the availability of |alpha|"
)
ctx
,
_
=
context
.
WithTimeout
(
context
.
Background
(),
timeout
)
o
.
exchange
.
HasBlock
(
ctx
,
alpha
)
time
.
Sleep
(
wait
)
t
.
Log
(
"I request |alpha| for myself."
)
ctx
,
_
=
context
.
WithTimeout
(
context
.
Background
(),
timeout
)
me
.
exchange
.
Block
(
ctx
,
alpha
.
Key
())
time
.
Sleep
(
wait
)
t
.
Log
(
"After receiving |f| from |o|, I send it to the wanting peer |w|"
)
block
,
err
:=
w
.
blockstore
.
Get
(
alpha
.
Key
())
if
err
!=
nil
{
t
.
Fatal
(
"Should not have received an error"
)
}
if
block
.
Key
()
!=
alpha
.
Key
()
{
t
.
Error
(
"Expected to receive alpha from me"
)
}
}
func
NewBlockGenerator
(
t
*
testing
.
T
)
BlockGenerator
{
...
...
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