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
9c59e0f0
Commit
9c59e0f0
authored
Nov 23, 2014
by
Brian Tiger Chow
Committed by
Jeromy
Dec 05, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(bitswap) build-breaking compilation errors
License: MIT Signed-off-by:
Brian Tiger Chow
<
brian@perfmode.com
>
parent
f56f5506
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
30 deletions
+30
-30
bitswap_test.go
bitswap_test.go
+30
-30
No files found.
bitswap_test.go
View file @
9c59e0f0
...
...
@@ -25,8 +25,8 @@ func TestClose(t *testing.T) {
block
:=
bgen
.
Next
()
bitswap
:=
sesgen
.
Next
()
bitswap
.
e
xchange
.
Close
()
bitswap
.
e
xchange
.
GetBlock
(
context
.
Background
(),
block
.
Key
())
bitswap
.
E
xchange
.
Close
()
bitswap
.
E
xchange
.
GetBlock
(
context
.
Background
(),
block
.
Key
())
}
func
TestGetBlockTimeout
(
t
*
testing
.
T
)
{
...
...
@@ -39,7 +39,7 @@ func TestGetBlockTimeout(t *testing.T) {
ctx
,
_
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Nanosecond
)
block
:=
blocks
.
NewBlock
([]
byte
(
"block"
))
_
,
err
:=
self
.
e
xchange
.
GetBlock
(
ctx
,
block
.
Key
())
_
,
err
:=
self
.
E
xchange
.
GetBlock
(
ctx
,
block
.
Key
())
if
err
!=
context
.
DeadlineExceeded
{
t
.
Fatal
(
"Expected DeadlineExceeded error"
)
...
...
@@ -58,7 +58,7 @@ func TestProviderForKeyButNetworkCannotFind(t *testing.T) {
solo
:=
g
.
Next
()
ctx
,
_
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Nanosecond
)
_
,
err
:=
solo
.
e
xchange
.
GetBlock
(
ctx
,
block
.
Key
())
_
,
err
:=
solo
.
E
xchange
.
GetBlock
(
ctx
,
block
.
Key
())
if
err
!=
context
.
DeadlineExceeded
{
t
.
Fatal
(
"Expected DeadlineExceeded error"
)
...
...
@@ -76,17 +76,17 @@ func TestGetBlockFromPeerAfterPeerAnnounces(t *testing.T) {
hasBlock
:=
g
.
Next
()
if
err
:=
hasBlock
.
b
lockstore
.
Put
(
block
);
err
!=
nil
{
if
err
:=
hasBlock
.
B
lockstore
.
Put
(
block
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
err
:=
hasBlock
.
e
xchange
.
HasBlock
(
context
.
Background
(),
block
);
err
!=
nil
{
if
err
:=
hasBlock
.
E
xchange
.
HasBlock
(
context
.
Background
(),
block
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
wantsBlock
:=
g
.
Next
()
ctx
,
_
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
)
received
,
err
:=
wantsBlock
.
e
xchange
.
GetBlock
(
ctx
,
block
.
Key
())
received
,
err
:=
wantsBlock
.
E
xchange
.
GetBlock
(
ctx
,
block
.
Key
())
if
err
!=
nil
{
t
.
Log
(
err
)
t
.
Fatal
(
"Expected to succeed"
)
...
...
@@ -135,9 +135,9 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
first
:=
instances
[
0
]
for
_
,
b
:=
range
blocks
{
first
.
b
lockstore
.
Put
(
b
)
first
.
e
xchange
.
HasBlock
(
context
.
Background
(),
b
)
rs
.
Announce
(
first
.
p
eer
,
b
.
Key
())
first
.
B
lockstore
.
Put
(
b
)
first
.
E
xchange
.
HasBlock
(
context
.
Background
(),
b
)
rs
.
Announce
(
first
.
P
eer
,
b
.
Key
())
}
t
.
Log
(
"Distribute!"
)
...
...
@@ -158,7 +158,7 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
for
_
,
inst
:=
range
instances
{
for
_
,
b
:=
range
blocks
{
if
_
,
err
:=
inst
.
b
lockstore
.
Get
(
b
.
Key
());
err
!=
nil
{
if
_
,
err
:=
inst
.
B
lockstore
.
Get
(
b
.
Key
());
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
...
...
@@ -166,8 +166,8 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
}
func
getOrFail
(
bitswap
Instance
,
b
*
blocks
.
Block
,
t
*
testing
.
T
,
wg
*
sync
.
WaitGroup
)
{
if
_
,
err
:=
bitswap
.
b
lockstore
.
Get
(
b
.
Key
());
err
!=
nil
{
_
,
err
:=
bitswap
.
e
xchange
.
GetBlock
(
context
.
Background
(),
b
.
Key
())
if
_
,
err
:=
bitswap
.
B
lockstore
.
Get
(
b
.
Key
());
err
!=
nil
{
_
,
err
:=
bitswap
.
E
xchange
.
GetBlock
(
context
.
Background
(),
b
.
Key
())
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -190,50 +190,50 @@ func TestSendToWantingPeer(t *testing.T) {
w
:=
sg
.
Next
()
o
:=
sg
.
Next
()
t
.
Logf
(
"Session %v
\n
"
,
me
.
p
eer
)
t
.
Logf
(
"Session %v
\n
"
,
w
.
p
eer
)
t
.
Logf
(
"Session %v
\n
"
,
o
.
p
eer
)
t
.
Logf
(
"Session %v
\n
"
,
me
.
P
eer
)
t
.
Logf
(
"Session %v
\n
"
,
w
.
P
eer
)
t
.
Logf
(
"Session %v
\n
"
,
o
.
P
eer
)
alpha
:=
bg
.
Next
()
const
timeout
=
100
*
time
.
Millisecond
// FIXME don't depend on time
t
.
Logf
(
"Peer %v attempts to get %v. NB: not available
\n
"
,
w
.
p
eer
,
alpha
.
Key
())
t
.
Logf
(
"Peer %v attempts to get %v. NB: not available
\n
"
,
w
.
P
eer
,
alpha
.
Key
())
ctx
,
_
:=
context
.
WithTimeout
(
context
.
Background
(),
timeout
)
_
,
err
:=
w
.
e
xchange
.
GetBlock
(
ctx
,
alpha
.
Key
())
_
,
err
:=
w
.
E
xchange
.
GetBlock
(
ctx
,
alpha
.
Key
())
if
err
==
nil
{
t
.
Fatalf
(
"Expected %v to NOT be available"
,
alpha
.
Key
())
}
beta
:=
bg
.
Next
()
t
.
Logf
(
"Peer %v announes availability of %v
\n
"
,
w
.
p
eer
,
beta
.
Key
())
t
.
Logf
(
"Peer %v announes availability of %v
\n
"
,
w
.
P
eer
,
beta
.
Key
())
ctx
,
_
=
context
.
WithTimeout
(
context
.
Background
(),
timeout
)
if
err
:=
w
.
b
lockstore
.
Put
(
beta
);
err
!=
nil
{
if
err
:=
w
.
B
lockstore
.
Put
(
beta
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
w
.
e
xchange
.
HasBlock
(
ctx
,
beta
)
w
.
E
xchange
.
HasBlock
(
ctx
,
beta
)
t
.
Logf
(
"%v gets %v from %v and discovers it wants %v
\n
"
,
me
.
p
eer
,
beta
.
Key
(),
w
.
p
eer
,
alpha
.
Key
())
t
.
Logf
(
"%v gets %v from %v and discovers it wants %v
\n
"
,
me
.
P
eer
,
beta
.
Key
(),
w
.
P
eer
,
alpha
.
Key
())
ctx
,
_
=
context
.
WithTimeout
(
context
.
Background
(),
timeout
)
if
_
,
err
:=
me
.
e
xchange
.
GetBlock
(
ctx
,
beta
.
Key
());
err
!=
nil
{
if
_
,
err
:=
me
.
E
xchange
.
GetBlock
(
ctx
,
beta
.
Key
());
err
!=
nil
{
t
.
Fatal
(
err
)
}
t
.
Logf
(
"%v announces availability of %v
\n
"
,
o
.
p
eer
,
alpha
.
Key
())
t
.
Logf
(
"%v announces availability of %v
\n
"
,
o
.
P
eer
,
alpha
.
Key
())
ctx
,
_
=
context
.
WithTimeout
(
context
.
Background
(),
timeout
)
if
err
:=
o
.
b
lockstore
.
Put
(
alpha
);
err
!=
nil
{
if
err
:=
o
.
B
lockstore
.
Put
(
alpha
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
o
.
e
xchange
.
HasBlock
(
ctx
,
alpha
)
o
.
E
xchange
.
HasBlock
(
ctx
,
alpha
)
t
.
Logf
(
"%v requests %v
\n
"
,
me
.
p
eer
,
alpha
.
Key
())
t
.
Logf
(
"%v requests %v
\n
"
,
me
.
P
eer
,
alpha
.
Key
())
ctx
,
_
=
context
.
WithTimeout
(
context
.
Background
(),
timeout
)
if
_
,
err
:=
me
.
e
xchange
.
GetBlock
(
ctx
,
alpha
.
Key
());
err
!=
nil
{
if
_
,
err
:=
me
.
E
xchange
.
GetBlock
(
ctx
,
alpha
.
Key
());
err
!=
nil
{
t
.
Fatal
(
err
)
}
t
.
Logf
(
"%v should now have %v
\n
"
,
w
.
p
eer
,
alpha
.
Key
())
block
,
err
:=
w
.
b
lockstore
.
Get
(
alpha
.
Key
())
t
.
Logf
(
"%v should now have %v
\n
"
,
w
.
P
eer
,
alpha
.
Key
())
block
,
err
:=
w
.
B
lockstore
.
Get
(
alpha
.
Key
())
if
err
!=
nil
{
t
.
Fatal
(
"Should not have received an error"
)
}
...
...
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