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
df4c1d82
Unverified
Commit
df4c1d82
authored
Apr 08, 2020
by
Will Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
additional tests
parent
0793dcde
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
2 deletions
+69
-2
dual/dual_test.go
dual/dual_test.go
+69
-2
No files found.
dual/dual_test.go
View file @
df4c1d82
...
...
@@ -147,7 +147,7 @@ func setupTier(ctx context.Context, t *testing.T) (*DHT, *dht.IpfsDHT, *dht.Ipfs
t
.
Fatal
(
err
)
}
hlprs
[
0
]
.
allow
=
wan
.
PeerID
()
connect
(
ctx
,
t
,
wan
,
d
.
WAN
)
connect
(
ctx
,
t
,
d
.
WAN
,
wan
)
lan
,
err
:=
dht
.
New
(
ctx
,
...
...
@@ -193,7 +193,7 @@ func TestFindProviderAsync(t *testing.T) {
defer
wan
.
Close
()
defer
lan
.
Close
()
if
err
:=
wan
.
Provide
(
ctx
,
wancid
,
tru
e
);
err
!=
nil
{
if
err
:=
wan
.
Provide
(
ctx
,
wancid
,
fals
e
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -221,3 +221,70 @@ func TestFindProviderAsync(t *testing.T) {
t
.
Fatal
(
"find provider timeout."
)
}
}
func
TestValueGetSet
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
20
*
time
.
Second
)
defer
cancel
()
d
,
wan
,
lan
:=
setupTier
(
ctx
,
t
)
defer
d
.
Close
()
defer
wan
.
Close
()
defer
lan
.
Close
()
err
:=
d
.
PutValue
(
ctx
,
"/v/hello"
,
[]
byte
(
"world"
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
val
,
err
:=
wan
.
GetValue
(
ctx
,
"/v/hello"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
string
(
val
)
!=
"world"
{
t
.
Fatal
(
"failed to get expected string."
)
}
val
,
err
=
lan
.
GetValue
(
ctx
,
"/v/hello"
)
if
err
==
nil
{
t
.
Fatal
(
err
)
}
}
func
TestSearchValue
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
20
*
time
.
Second
)
defer
cancel
()
d
,
wan
,
lan
:=
setupTier
(
ctx
,
t
)
defer
d
.
Close
()
defer
wan
.
Close
()
defer
lan
.
Close
()
err
:=
wan
.
PutValue
(
ctx
,
"/v/hello"
,
[]
byte
(
"world"
),
)
valCh
,
err
:=
d
.
SearchValue
(
ctx
,
"/v/hello"
,
dht
.
Quorum
(
0
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
select
{
case
v
:=
<-
valCh
:
if
string
(
v
)
!=
"world"
{
t
.
Errorf
(
"expected 'world', got '%s'"
,
string
(
v
))
}
case
<-
ctx
.
Done
()
:
t
.
Fatal
(
ctx
.
Err
())
}
err
=
lan
.
PutValue
(
ctx
,
"/v/hello"
,
[]
byte
(
"newer"
))
if
err
!=
nil
{
t
.
Error
(
err
)
}
select
{
case
v
:=
<-
valCh
:
if
string
(
v
)
!=
"newer"
{
t
.
Errorf
(
"expected 'newer', got '%s'"
,
string
(
v
))
}
case
<-
ctx
.
Done
()
:
t
.
Fatal
(
ctx
.
Err
())
}
}
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