Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
d9eab0c4
Unverified
Commit
d9eab0c4
authored
Jun 30, 2020
by
acud
Committed by
GitHub
Jun 30, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix puller test, add cleanups to kademlia (#397)
parent
1ece1e66
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
7 deletions
+28
-7
kademlia_test.go
pkg/kademlia/kademlia_test.go
+13
-5
puller_test.go
pkg/puller/puller_test.go
+15
-2
No files found.
pkg/kademlia/kademlia_test.go
View file @
d9eab0c4
...
@@ -260,6 +260,7 @@ func TestNotifierHooks(t *testing.T) {
...
@@ -260,6 +260,7 @@ func TestNotifierHooks(t *testing.T) {
peer
=
test
.
RandomAddressAt
(
base
,
3
)
peer
=
test
.
RandomAddressAt
(
base
,
3
)
addr
=
test
.
RandomAddressAt
(
peer
,
4
)
// address which is closer to peer
addr
=
test
.
RandomAddressAt
(
peer
,
4
)
// address which is closer to peer
)
)
defer
kad
.
Close
()
connectOne
(
t
,
signer
,
kad
,
ab
,
peer
)
connectOne
(
t
,
signer
,
kad
,
ab
,
peer
)
...
@@ -289,6 +290,7 @@ func TestDiscoveryHooks(t *testing.T) {
...
@@ -289,6 +290,7 @@ func TestDiscoveryHooks(t *testing.T) {
_
,
kad
,
ab
,
disc
,
signer
=
newTestKademlia
(
&
conns
,
nil
,
nil
)
_
,
kad
,
ab
,
disc
,
signer
=
newTestKademlia
(
&
conns
,
nil
,
nil
)
p1
,
p2
,
p3
=
test
.
RandomAddress
(),
test
.
RandomAddress
(),
test
.
RandomAddress
()
p1
,
p2
,
p3
=
test
.
RandomAddress
(),
test
.
RandomAddress
(),
test
.
RandomAddress
()
)
)
defer
kad
.
Close
()
// first add a peer from AddPeer, wait for the connection
// first add a peer from AddPeer, wait for the connection
addOne
(
t
,
signer
,
kad
,
ab
,
p1
)
addOne
(
t
,
signer
,
kad
,
ab
,
p1
)
...
@@ -319,10 +321,10 @@ func TestBackoff(t *testing.T) {
...
@@ -319,10 +321,10 @@ func TestBackoff(t *testing.T) {
*
kademlia
.
TimeToRetry
=
500
*
time
.
Millisecond
*
kademlia
.
TimeToRetry
=
500
*
time
.
Millisecond
var
(
var
(
conns
int32
// how many connect calls were made to the p2p mock
conns
int32
// how many connect calls were made to the p2p mock
base
,
kad
,
ab
,
_
,
signer
=
newTestKademlia
(
&
conns
,
nil
,
nil
)
base
,
kad
,
ab
,
_
,
signer
=
newTestKademlia
(
&
conns
,
nil
,
nil
)
)
)
defer
kad
.
Close
()
// add one peer, wait for connection
// add one peer, wait for connection
addr
:=
test
.
RandomAddressAt
(
base
,
1
)
addr
:=
test
.
RandomAddressAt
(
base
,
1
)
...
@@ -361,6 +363,7 @@ func TestAddressBookPrune(t *testing.T) {
...
@@ -361,6 +363,7 @@ func TestAddressBookPrune(t *testing.T) {
conns
,
failedConns
int32
// how many connect calls were made to the p2p mock
conns
,
failedConns
int32
// how many connect calls were made to the p2p mock
base
,
kad
,
ab
,
_
,
signer
=
newTestKademlia
(
&
conns
,
&
failedConns
,
nil
)
base
,
kad
,
ab
,
_
,
signer
=
newTestKademlia
(
&
conns
,
&
failedConns
,
nil
)
)
)
defer
kad
.
Close
()
nonConnPeer
,
err
:=
bzz
.
NewAddress
(
signer
,
nonConnectableAddress
,
test
.
RandomAddressAt
(
base
,
1
),
0
)
nonConnPeer
,
err
:=
bzz
.
NewAddress
(
signer
,
nonConnectableAddress
,
test
.
RandomAddressAt
(
base
,
1
),
0
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -525,6 +528,7 @@ func TestKademlia_SubscribePeersChange(t *testing.T) {
...
@@ -525,6 +528,7 @@ func TestKademlia_SubscribePeersChange(t *testing.T) {
t
.
Run
(
"single subscription"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"single subscription"
,
func
(
t
*
testing
.
T
)
{
base
,
kad
,
ab
,
_
,
sg
:=
newTestKademlia
(
nil
,
nil
,
nil
)
base
,
kad
,
ab
,
_
,
sg
:=
newTestKademlia
(
nil
,
nil
,
nil
)
defer
kad
.
Close
()
c
,
u
:=
kad
.
SubscribePeersChange
()
c
,
u
:=
kad
.
SubscribePeersChange
()
defer
u
()
defer
u
()
...
@@ -537,6 +541,7 @@ func TestKademlia_SubscribePeersChange(t *testing.T) {
...
@@ -537,6 +541,7 @@ func TestKademlia_SubscribePeersChange(t *testing.T) {
t
.
Run
(
"single subscription, remove peer"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"single subscription, remove peer"
,
func
(
t
*
testing
.
T
)
{
base
,
kad
,
ab
,
_
,
sg
:=
newTestKademlia
(
nil
,
nil
,
nil
)
base
,
kad
,
ab
,
_
,
sg
:=
newTestKademlia
(
nil
,
nil
,
nil
)
defer
kad
.
Close
()
c
,
u
:=
kad
.
SubscribePeersChange
()
c
,
u
:=
kad
.
SubscribePeersChange
()
defer
u
()
defer
u
()
...
@@ -552,6 +557,7 @@ func TestKademlia_SubscribePeersChange(t *testing.T) {
...
@@ -552,6 +557,7 @@ func TestKademlia_SubscribePeersChange(t *testing.T) {
t
.
Run
(
"multiple subscriptions"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"multiple subscriptions"
,
func
(
t
*
testing
.
T
)
{
base
,
kad
,
ab
,
_
,
sg
:=
newTestKademlia
(
nil
,
nil
,
nil
)
base
,
kad
,
ab
,
_
,
sg
:=
newTestKademlia
(
nil
,
nil
,
nil
)
defer
kad
.
Close
()
c1
,
u1
:=
kad
.
SubscribePeersChange
()
c1
,
u1
:=
kad
.
SubscribePeersChange
()
defer
u1
()
defer
u1
()
...
@@ -569,6 +575,7 @@ func TestKademlia_SubscribePeersChange(t *testing.T) {
...
@@ -569,6 +575,7 @@ func TestKademlia_SubscribePeersChange(t *testing.T) {
t
.
Run
(
"multiple changes"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"multiple changes"
,
func
(
t
*
testing
.
T
)
{
base
,
kad
,
ab
,
_
,
sg
:=
newTestKademlia
(
nil
,
nil
,
nil
)
base
,
kad
,
ab
,
_
,
sg
:=
newTestKademlia
(
nil
,
nil
,
nil
)
defer
kad
.
Close
()
c
,
u
:=
kad
.
SubscribePeersChange
()
c
,
u
:=
kad
.
SubscribePeersChange
()
defer
u
()
defer
u
()
...
@@ -590,6 +597,7 @@ func TestKademlia_SubscribePeersChange(t *testing.T) {
...
@@ -590,6 +597,7 @@ func TestKademlia_SubscribePeersChange(t *testing.T) {
t
.
Run
(
"no depth change"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"no depth change"
,
func
(
t
*
testing
.
T
)
{
_
,
kad
,
_
,
_
,
_
:=
newTestKademlia
(
nil
,
nil
,
nil
)
_
,
kad
,
_
,
_
,
_
:=
newTestKademlia
(
nil
,
nil
,
nil
)
defer
kad
.
Close
()
c
,
u
:=
kad
.
SubscribePeersChange
()
c
,
u
:=
kad
.
SubscribePeersChange
()
defer
u
()
defer
u
()
...
@@ -607,9 +615,9 @@ func TestKademlia_SubscribePeersChange(t *testing.T) {
...
@@ -607,9 +615,9 @@ func TestKademlia_SubscribePeersChange(t *testing.T) {
}
}
func
TestMarshal
(
t
*
testing
.
T
)
{
func
TestMarshal
(
t
*
testing
.
T
)
{
var
(
_
,
kad
,
ab
,
_
,
signer
:=
newTestKademlia
(
nil
,
nil
,
nil
)
_
,
kad
,
ab
,
_
,
signer
=
newTestKademlia
(
nil
,
nil
,
nil
)
defer
kad
.
Close
(
)
)
a
:=
test
.
RandomAddress
()
a
:=
test
.
RandomAddress
()
addOne
(
t
,
signer
,
kad
,
ab
,
a
)
addOne
(
t
,
signer
,
kad
,
ab
,
a
)
_
,
err
:=
kad
.
MarshalJSON
()
_
,
err
:=
kad
.
MarshalJSON
()
...
...
pkg/puller/puller_test.go
View file @
d9eab0c4
...
@@ -201,7 +201,7 @@ func TestSyncFlow_PeerOutsideDepth_Historical(t *testing.T) {
...
@@ -201,7 +201,7 @@ func TestSyncFlow_PeerOutsideDepth_Historical(t *testing.T) {
kad
.
Trigger
()
kad
.
Trigger
()
waitCursorsCalled
(
t
,
pullsync
,
addr
,
false
)
waitCursorsCalled
(
t
,
pullsync
,
addr
,
false
)
waitSyncCalled
(
t
,
pullsync
,
addr
,
false
)
waitSyncCalled
Times
(
t
,
pullsync
,
addr
,
len
(
tc
.
expCalls
)
)
// check historical sync calls
// check historical sync calls
checkCalls
(
t
,
tc
.
expCalls
,
pullsync
.
SyncCalls
(
addr
))
checkCalls
(
t
,
tc
.
expCalls
,
pullsync
.
SyncCalls
(
addr
))
...
@@ -479,7 +479,7 @@ func checkCallsUnordered(t *testing.T, expCalls []c, calls []mockps.SyncCall) {
...
@@ -479,7 +479,7 @@ func checkCallsUnordered(t *testing.T, expCalls []c, calls []mockps.SyncCall) {
}
}
}
}
// wait
SyncCalled waits until SyncInterval is called on the address given
.
// wait
CursorsCalled waits until GetCursors are called on the given address
.
func
waitCursorsCalled
(
t
*
testing
.
T
,
ps
*
mockps
.
PullSyncMock
,
addr
swarm
.
Address
,
invert
bool
)
{
func
waitCursorsCalled
(
t
*
testing
.
T
,
ps
*
mockps
.
PullSyncMock
,
addr
swarm
.
Address
,
invert
bool
)
{
t
.
Helper
()
t
.
Helper
()
for
i
:=
0
;
i
<
20
;
i
++
{
for
i
:=
0
;
i
<
20
;
i
++
{
...
@@ -541,6 +541,19 @@ func waitSyncCalled(t *testing.T, ps *mockps.PullSyncMock, addr swarm.Address, i
...
@@ -541,6 +541,19 @@ func waitSyncCalled(t *testing.T, ps *mockps.PullSyncMock, addr swarm.Address, i
t
.
Fatal
(
"timed out waiting for sync"
)
t
.
Fatal
(
"timed out waiting for sync"
)
}
}
func
waitSyncCalledTimes
(
t
*
testing
.
T
,
ps
*
mockps
.
PullSyncMock
,
addr
swarm
.
Address
,
times
int
)
{
t
.
Helper
()
for
i
:=
0
;
i
<
15
;
i
++
{
v
:=
ps
.
SyncCalls
(
addr
)
if
len
(
v
)
==
times
{
return
}
time
.
Sleep
(
50
*
time
.
Millisecond
)
}
t
.
Fatal
(
"timed out waiting for sync"
)
}
type
opts
struct
{
type
opts
struct
{
pullSync
[]
mockps
.
Option
pullSync
[]
mockps
.
Option
kad
[]
mockk
.
Option
kad
[]
mockk
.
Option
...
...
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