Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
d7c4c0a2
Commit
d7c4c0a2
authored
7 years ago
by
Steven Allen
Browse files
Options
Download
Email Patches
Plain Diff
add test for forgetting address records
parent
ea95a94e
master
2018-Q4-OKR
feat/protobuf
fix/473
fix/no-custom-field
fix/reset-ping-stream
fix/revert-correct-external-addr
gx/update-nza0mn
jenkinsfile
multistream-ping
punching
revert-276-update-go-detect-race
v6.0.23
v6.0.22
v6.0.21
v6.0.20
v6.0.19
v6.0.18
v6.0.17
v6.0.16
v6.0.15
v6.0.14
v6.0.13
v6.0.12
v6.0.11
v6.0.10
v6.0.9
v6.0.8
v6.0.7
v6.0.6
v6.0.5
v6.0.4
v6.0.3
v6.0.2
v6.0.1
v6.0.0
v5.0.21
v5.0.20
v5.0.19
v5.0.18
v5.0.17
v5.0.16
v5.0.15
v5.0.14
v5.0.13
v5.0.12
v5.0.11
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
p2p/protocol/identify/id_test.go
+40
-11
p2p/protocol/identify/id_test.go
with
40 additions
and
11 deletions
+40
-11
p2p/protocol/identify/id_test.go
View file @
d7c4c0a2
...
...
@@ -8,6 +8,7 @@ import (
ic
"github.com/libp2p/go-libp2p-crypto"
testutil
"github.com/libp2p/go-libp2p-netutil"
peer
"github.com/libp2p/go-libp2p-peer"
pstore
"github.com/libp2p/go-libp2p-peerstore"
identify
"github.com/libp2p/go-libp2p/p2p/protocol/identify"
blhost
"github.com/libp2p/go-libp2p-blankhost"
...
...
@@ -15,9 +16,10 @@ import (
ma
"github.com/multiformats/go-multiaddr"
)
func
subtestIDService
(
t
*
testing
.
T
,
postDialWait
time
.
Duration
)
{
func
subtestIDService
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
ctx
:=
context
.
Background
()
h1
:=
blhost
.
NewBlankHost
(
testutil
.
GenSwarmNetwork
(
t
,
ctx
))
h2
:=
blhost
.
NewBlankHost
(
testutil
.
GenSwarmNetwork
(
t
,
ctx
))
...
...
@@ -30,6 +32,11 @@ func subtestIDService(t *testing.T, postDialWait time.Duration) {
testKnowsAddrs
(
t
,
h1
,
h2p
,
[]
ma
.
Multiaddr
{})
// nothing
testKnowsAddrs
(
t
,
h2
,
h1p
,
[]
ma
.
Multiaddr
{})
// nothing
forgetMe
,
_
:=
ma
.
NewMultiaddr
(
"/ip4/1.2.3.4/tcp/1234"
)
h2
.
Peerstore
()
.
AddAddr
(
h1p
,
forgetMe
,
pstore
.
RecentlyConnectedAddrTTL
)
time
.
Sleep
(
50
*
time
.
Millisecond
)
h2pi
:=
h2
.
Peerstore
()
.
PeerInfo
(
h2p
)
if
err
:=
h1
.
Connect
(
ctx
,
h2pi
);
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -58,16 +65,39 @@ func subtestIDService(t *testing.T, postDialWait time.Duration) {
ids2
.
IdentifyConn
(
c
[
0
])
addrs
:=
h1
.
Peerstore
()
.
Addrs
(
h1p
)
addrs
=
append
(
addrs
,
c
[
0
]
.
RemoteMultiaddr
())
addrs
=
append
(
addrs
,
c
[
0
]
.
RemoteMultiaddr
()
,
forgetMe
)
// and the protocol versions.
t
.
Log
(
"test peer2 has peer1 addrs correctly"
)
testKnowsAddrs
(
t
,
h2
,
h1p
,
addrs
)
// has them
testHasProtocolVersions
(
t
,
h2
,
h1p
)
testHasPublicKey
(
t
,
h2
,
h1p
,
h1
.
Peerstore
()
.
PubKey
(
h1p
))
// h1 should have h2's public key
// Need both sides to actually notice that the connection has been closed.
h1
.
Network
()
.
ClosePeer
(
h2p
)
h2
.
Network
()
.
ClosePeer
(
h1p
)
if
len
(
h2
.
Network
()
.
ConnsToPeer
(
h1
.
ID
()))
!=
0
||
len
(
h1
.
Network
()
.
ConnsToPeer
(
h2
.
ID
()))
!=
0
{
t
.
Fatal
(
"should have no connections"
)
}
testKnowsAddrs
(
t
,
h2
,
h1p
,
addrs
)
testKnowsAddrs
(
t
,
h1
,
h2p
,
h2
.
Peerstore
()
.
Addrs
(
h2p
))
time
.
Sleep
(
50
*
time
.
Millisecond
)
// Forget the first one.
testKnowsAddrs
(
t
,
h2
,
h1p
,
addrs
[
:
len
(
addrs
)
-
1
])
time
.
Sleep
(
50
*
time
.
Millisecond
)
// Forget the rest.
testKnowsAddrs
(
t
,
h1
,
h2p
,
[]
ma
.
Multiaddr
{})
testKnowsAddrs
(
t
,
h2
,
h1p
,
[]
ma
.
Multiaddr
{})
}
func
testKnowsAddrs
(
t
*
testing
.
T
,
h
host
.
Host
,
p
peer
.
ID
,
expected
[]
ma
.
Multiaddr
)
{
t
.
Helper
()
actual
:=
h
.
Peerstore
()
.
Addrs
(
p
)
if
len
(
actual
)
!=
len
(
expected
)
{
...
...
@@ -125,17 +155,16 @@ func testHasPublicKey(t *testing.T, h host.Host, p peer.ID, shouldBe ic.PubKey)
// TestIDServiceWait gives the ID service 100ms to finish after dialing
// this is becasue it used to be concurrent. Now, Dial wait till the
// id service is done.
func
TestIDService
Wait
(
t
*
testing
.
T
)
{
N
:=
3
for
i
:=
0
;
i
<
N
;
i
++
{
subtestIDService
(
t
,
100
*
time
.
Millisecond
)
}
}
func
TestIDService
(
t
*
testing
.
T
)
{
oldTTL
:=
pstore
.
RecentlyConnectedAddrTTL
pstore
.
RecentlyConnectedAddrTTL
=
100
*
time
.
Millisecond
defer
func
()
{
pstore
.
RecentlyConnectedAddrTTL
=
oldTTL
}()
func
TestIDServiceNoWait
(
t
*
testing
.
T
)
{
N
:=
3
for
i
:=
0
;
i
<
N
;
i
++
{
subtestIDService
(
t
,
0
)
subtestIDService
(
t
)
}
}
...
...
This diff is collapsed.
Click to expand it.
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
Menu
Projects
Groups
Snippets
Help