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
5bb50b8d
Commit
5bb50b8d
authored
Apr 18, 2019
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
providers: test partial GC
parent
e4d739c9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
7 deletions
+31
-7
providers/providers_test.go
providers/providers_test.go
+31
-7
No files found.
providers/providers_test.go
View file @
5bb50b8d
...
...
@@ -129,38 +129,62 @@ func TestProvidesExpire(t *testing.T) {
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
ds
:=
dssync
.
MutexWrap
(
ds
.
NewMapDatastore
())
mid
:=
peer
.
ID
(
"testing"
)
p
:=
NewProviderManager
(
ctx
,
mid
,
ds
sync
.
MutexWrap
(
ds
.
NewMapDatastore
())
)
p
:=
NewProviderManager
(
ctx
,
mid
,
ds
)
peers
:=
[]
peer
.
ID
{
"a"
,
"b"
}
var
cids
[]
cid
.
Cid
for
i
:=
0
;
i
<
10
;
i
++
{
c
:=
cid
.
NewCidV0
(
u
.
Hash
([]
byte
(
fmt
.
Sprint
(
i
))))
cids
=
append
(
cids
,
c
)
}
for
_
,
c
:=
range
cids
[
:
5
]
{
p
.
AddProvider
(
ctx
,
c
,
peers
[
0
])
p
.
AddProvider
(
ctx
,
c
,
peers
[
1
])
}
for
i
:=
0
;
i
<
10
;
i
++
{
out
:=
p
.
GetProviders
(
ctx
,
cids
[
i
])
time
.
Sleep
(
time
.
Second
/
4
)
for
_
,
c
:=
range
cids
[
5
:
]
{
p
.
AddProvider
(
ctx
,
c
,
peers
[
0
])
p
.
AddProvider
(
ctx
,
c
,
peers
[
1
])
}
for
_
,
c
:=
range
cids
{
out
:=
p
.
GetProviders
(
ctx
,
c
)
if
len
(
out
)
!=
2
{
t
.
Fatal
(
"expected providers to still be there"
)
}
}
time
.
Sleep
(
time
.
Second
)
for
i
:=
0
;
i
<
10
;
i
++
{
out
:=
p
.
GetProviders
(
ctx
,
cids
[
i
])
time
.
Sleep
(
3
*
time
.
Second
/
8
)
for
_
,
c
:=
range
cids
[
:
5
]
{
out
:=
p
.
GetProviders
(
ctx
,
c
)
if
len
(
out
)
>
0
{
t
.
Fatal
(
"expected providers to be cleaned up, got: "
,
out
)
}
}
for
_
,
c
:=
range
cids
[
5
:
]
{
out
:=
p
.
GetProviders
(
ctx
,
c
)
if
len
(
out
)
!=
2
{
t
.
Fatal
(
"expected providers to still be there"
)
}
}
time
.
Sleep
(
time
.
Second
/
2
)
// Stop to prevent data races
p
.
Process
()
.
Close
()
if
p
.
providers
.
Len
()
!=
0
{
t
.
Fatal
(
"providers map not cleaned up"
)
}
res
,
err
:=
p
.
dstore
.
Query
(
dsq
.
Query
{
Prefix
:
providersKeyPrefix
})
res
,
err
:=
ds
.
Query
(
dsq
.
Query
{
Prefix
:
providersKeyPrefix
})
if
err
!=
nil
{
t
.
Fatal
(
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