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-pubsub
Commits
4336d5ae
Commit
4336d5ae
authored
Dec 06, 2020
by
Adin Schmahmann
Committed by
vyzo
Dec 07, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: add test for if nodes are connected before pubsub is started
parent
08c17398
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
0 deletions
+63
-0
floodsub_test.go
floodsub_test.go
+63
-0
No files found.
floodsub_test.go
View file @
4336d5ae
...
...
@@ -1137,3 +1137,66 @@ func TestWithInvalidMessageAuthor(t *testing.T) {
t
.
Fatal
(
"expected error"
)
}
}
func
TestPreconnectedNodes
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
// If this test fails it may hang so set a timeout
ctx
,
cancel
=
context
.
WithTimeout
(
ctx
,
time
.
Second
*
10
)
defer
cancel
()
// Create hosts
h1
:=
bhost
.
NewBlankHost
(
swarmt
.
GenSwarm
(
t
,
ctx
))
h2
:=
bhost
.
NewBlankHost
(
swarmt
.
GenSwarm
(
t
,
ctx
))
opts
:=
[]
Option
{
WithDiscovery
(
&
dummyDiscovery
{})}
// Setup first PubSub
p1
,
err
:=
NewFloodSub
(
ctx
,
h1
,
opts
...
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Connect the two hosts together
connect
(
t
,
h2
,
h1
)
// Setup the second DHT
p2
,
err
:=
NewFloodSub
(
ctx
,
h2
,
opts
...
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// See if it works
p2Topic
,
err
:=
p2
.
Join
(
"test"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
p1Topic
,
err
:=
p1
.
Join
(
"test"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
testPublish
:=
func
(
publisher
,
receiver
*
Topic
,
msg
[]
byte
)
{
receiverSub
,
err
:=
receiver
.
Subscribe
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
err
:=
publisher
.
Publish
(
ctx
,
msg
,
WithReadiness
(
MinTopicSize
(
1
)));
err
!=
nil
{
t
.
Fatal
(
err
)
}
m
,
err
:=
receiverSub
.
Next
(
ctx
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
receivedData
:=
m
.
GetData
();
!
bytes
.
Equal
(
receivedData
,
msg
)
{
t
.
Fatalf
(
"expected message %v, got %v"
,
msg
,
receivedData
)
}
}
// Test both directions since PubSub uses one directional streams
testPublish
(
p1Topic
,
p2Topic
,
[]
byte
(
"test1-to-2"
))
testPublish
(
p1Topic
,
p2Topic
,
[]
byte
(
"test2-to-1"
))
}
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