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-swarm
Commits
43b03828
Commit
43b03828
authored
Apr 01, 2021
by
vyzo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add new TestDialSelf
so that we exercise the dialWorker dial to self error path
parent
4a69fa2f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
7 deletions
+24
-7
dial_sync_test.go
dial_sync_test.go
+23
-0
dial_test.go
dial_test.go
+1
-7
No files found.
dial_sync_test.go
View file @
43b03828
...
@@ -270,3 +270,26 @@ func TestStressActiveDial(t *testing.T) {
...
@@ -270,3 +270,26 @@ func TestStressActiveDial(t *testing.T) {
wg
.
Wait
()
wg
.
Wait
()
}
}
func
TestDialSelf
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
self
:=
peer
.
ID
(
"ABC"
)
s
:=
NewSwarm
(
ctx
,
self
,
nil
,
nil
)
defer
s
.
Close
()
ds
:=
NewDialSync
(
s
.
dialWorker
)
// this should fail
_
,
err
:=
ds
.
DialLock
(
ctx
,
self
)
if
err
!=
ErrDialToSelf
{
t
.
Fatal
(
"expected error from self dial"
)
}
// do it twice to make sure we get a new active dial object that fails again
_
,
err
=
ds
.
DialLock
(
ctx
,
self
)
if
err
!=
ErrDialToSelf
{
t
.
Fatal
(
"expected error from self dial"
)
}
}
dial_test.go
View file @
43b03828
...
@@ -652,7 +652,7 @@ func TestDialSimultaneousJoin(t *testing.T) {
...
@@ -652,7 +652,7 @@ func TestDialSimultaneousJoin(t *testing.T) {
}
}
}
}
func
TestDialSelf
(
t
*
testing
.
T
)
{
func
TestDialSelf
2
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
defer
cancel
()
...
@@ -664,10 +664,4 @@ func TestDialSelf(t *testing.T) {
...
@@ -664,10 +664,4 @@ func TestDialSelf(t *testing.T) {
if
err
!=
ErrDialToSelf
{
if
err
!=
ErrDialToSelf
{
t
.
Fatal
(
"expected error from self dial"
)
t
.
Fatal
(
"expected error from self dial"
)
}
}
// do it twice to make sure we get a new active dial object that fails again
_
,
err
=
s1
.
DialPeer
(
ctx
,
s1
.
LocalPeer
())
if
err
!=
ErrDialToSelf
{
t
.
Fatal
(
"expected error from self dial"
)
}
}
}
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