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
p2p
go-p2p-kad-dht
Commits
2604f342
Commit
2604f342
authored
Sep 30, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make go vet happy
parent
1ac83501
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
12 deletions
+24
-12
dht_test.go
dht_test.go
+20
-10
ext_test.go
ext_test.go
+4
-2
No files found.
dht_test.go
View file @
2604f342
...
...
@@ -164,7 +164,8 @@ func TestValueGetSet(t *testing.T) {
connect
(
t
,
ctx
,
dhtA
,
dhtB
)
log
.
Error
(
"adding value on: "
,
dhtA
.
self
)
ctxT
,
_
:=
context
.
WithTimeout
(
ctx
,
time
.
Second
)
ctxT
,
cancel
:=
context
.
WithTimeout
(
ctx
,
time
.
Second
)
defer
cancel
()
err
:=
dhtA
.
PutValue
(
ctxT
,
"/v/hello"
,
[]
byte
(
"world"
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -183,7 +184,8 @@ func TestValueGetSet(t *testing.T) {
*/
log
.
Error
(
"requesting value on dht: "
,
dhtB
.
self
)
ctxT
,
_
=
context
.
WithTimeout
(
ctx
,
time
.
Second
*
2
)
ctxT
,
cancel
=
context
.
WithTimeout
(
ctx
,
time
.
Second
*
2
)
defer
cancel
()
valb
,
err
:=
dhtB
.
GetValue
(
ctxT
,
"/v/hello"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -225,7 +227,8 @@ func TestProvides(t *testing.T) {
n
=
(
n
+
1
)
%
3
log
.
Debugf
(
"getting providers for %s from %d"
,
c
,
n
)
ctxT
,
_
:=
context
.
WithTimeout
(
ctx
,
time
.
Second
)
ctxT
,
cancel
:=
context
.
WithTimeout
(
ctx
,
time
.
Second
)
defer
cancel
()
provchan
:=
dhts
[
n
]
.
FindProvidersAsync
(
ctxT
,
c
,
1
)
select
{
...
...
@@ -317,7 +320,8 @@ func TestBootstrap(t *testing.T) {
go
func
()
{
for
{
t
.
Logf
(
"bootstrapping them so they find each other %d"
,
nDHTs
)
ctxT
,
_
:=
context
.
WithTimeout
(
ctx
,
5
*
time
.
Second
)
ctxT
,
cancel
:=
context
.
WithTimeout
(
ctx
,
5
*
time
.
Second
)
defer
cancel
()
bootstrap
(
t
,
ctxT
,
dhts
)
select
{
...
...
@@ -442,7 +446,8 @@ func TestProvidesMany(t *testing.T) {
<-
time
.
After
(
100
*
time
.
Millisecond
)
t
.
Logf
(
"bootstrapping them so they find each other. %d"
,
nDHTs
)
ctxT
,
_
:=
context
.
WithTimeout
(
ctx
,
20
*
time
.
Second
)
ctxT
,
cancel
:=
context
.
WithTimeout
(
ctx
,
20
*
time
.
Second
)
defer
cancel
()
bootstrap
(
t
,
ctxT
,
dhts
)
if
u
.
Debug
{
...
...
@@ -474,7 +479,8 @@ func TestProvidesMany(t *testing.T) {
errchan
:=
make
(
chan
error
)
ctxT
,
_
=
context
.
WithTimeout
(
ctx
,
5
*
time
.
Second
)
ctxT
,
cancel
=
context
.
WithTimeout
(
ctx
,
5
*
time
.
Second
)
defer
cancel
()
var
wg
sync
.
WaitGroup
getProvider
:=
func
(
dht
*
IpfsDHT
,
k
*
cid
.
Cid
)
{
...
...
@@ -544,7 +550,8 @@ func TestProvidesAsync(t *testing.T) {
time
.
Sleep
(
time
.
Millisecond
*
60
)
ctxT
,
_
:=
context
.
WithTimeout
(
ctx
,
time
.
Millisecond
*
300
)
ctxT
,
cancel
:=
context
.
WithTimeout
(
ctx
,
time
.
Millisecond
*
300
)
defer
cancel
()
provs
:=
dhts
[
0
]
.
FindProvidersAsync
(
ctxT
,
testCaseCids
[
0
],
5
)
select
{
case
p
,
ok
:=
<-
provs
:
...
...
@@ -585,7 +592,8 @@ func TestLayeredGet(t *testing.T) {
time
.
Sleep
(
time
.
Millisecond
*
6
)
ctxT
,
_
:=
context
.
WithTimeout
(
ctx
,
time
.
Second
)
ctxT
,
cancel
:=
context
.
WithTimeout
(
ctx
,
time
.
Second
)
defer
cancel
()
val
,
err
:=
dhts
[
0
]
.
GetValue
(
ctxT
,
"/v/hello"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -616,7 +624,8 @@ func TestFindPeer(t *testing.T) {
connect
(
t
,
ctx
,
dhts
[
1
],
dhts
[
2
])
connect
(
t
,
ctx
,
dhts
[
1
],
dhts
[
3
])
ctxT
,
_
:=
context
.
WithTimeout
(
ctx
,
time
.
Second
)
ctxT
,
cancel
:=
context
.
WithTimeout
(
ctx
,
time
.
Second
)
defer
cancel
()
p
,
err
:=
dhts
[
0
]
.
FindPeer
(
ctxT
,
peers
[
2
])
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -660,7 +669,8 @@ func TestFindPeersConnectedToPeer(t *testing.T) {
// fmt.Println("2 is", peers[2])
// fmt.Println("3 is", peers[3])
ctxT
,
_
:=
context
.
WithTimeout
(
ctx
,
time
.
Second
)
ctxT
,
cancel
:=
context
.
WithTimeout
(
ctx
,
time
.
Second
)
defer
cancel
()
pchan
,
err
:=
dhts
[
0
]
.
FindPeersConnectedToPeer
(
ctxT
,
peers
[
2
])
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
ext_test.go
View file @
2604f342
...
...
@@ -41,7 +41,8 @@ func TestGetFailures(t *testing.T) {
})
// This one should time out
ctx1
,
_
:=
context
.
WithTimeout
(
context
.
Background
(),
200
*
time
.
Millisecond
)
ctx1
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
200
*
time
.
Millisecond
)
defer
cancel
()
if
_
,
err
:=
d
.
GetValue
(
ctx1
,
"test"
);
err
!=
nil
{
if
merr
,
ok
:=
err
.
(
u
.
MultiErr
);
ok
&&
len
(
merr
)
>
0
{
err
=
merr
[
0
]
...
...
@@ -81,7 +82,8 @@ func TestGetFailures(t *testing.T) {
// the dht should be exhausting its query and returning not found.
// (was 3 seconds before which should be _plenty_ of time, but maybe
// travis machines really have a hard time...)
ctx2
,
_
:=
context
.
WithTimeout
(
context
.
Background
(),
20
*
time
.
Second
)
ctx2
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
20
*
time
.
Second
)
defer
cancel
()
_
,
err
=
d
.
GetValue
(
ctx2
,
"test"
)
if
err
!=
nil
{
if
merr
,
ok
:=
err
.
(
u
.
MultiErr
);
ok
&&
len
(
merr
)
>
0
{
...
...
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