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
b080f595
Commit
b080f595
authored
Jan 12, 2021
by
vyzo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add test for inbound stream deduplication
parent
8676a0e2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
0 deletions
+54
-0
floodsub_test.go
floodsub_test.go
+54
-0
No files found.
floodsub_test.go
View file @
b080f595
...
@@ -1200,3 +1200,57 @@ func TestPreconnectedNodes(t *testing.T) {
...
@@ -1200,3 +1200,57 @@ func TestPreconnectedNodes(t *testing.T) {
testPublish
(
p1Topic
,
p2Topic
,
[]
byte
(
"test1-to-2"
))
testPublish
(
p1Topic
,
p2Topic
,
[]
byte
(
"test1-to-2"
))
testPublish
(
p1Topic
,
p2Topic
,
[]
byte
(
"test2-to-1"
))
testPublish
(
p1Topic
,
p2Topic
,
[]
byte
(
"test2-to-1"
))
}
}
func
TestDedupInboundStreams
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
h1
:=
bhost
.
NewBlankHost
(
swarmt
.
GenSwarm
(
t
,
ctx
))
h2
:=
bhost
.
NewBlankHost
(
swarmt
.
GenSwarm
(
t
,
ctx
))
_
,
err
:=
NewFloodSub
(
ctx
,
h1
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Connect the two hosts together
connect
(
t
,
h2
,
h1
)
// open a few streams and make sure all but the last one get reset
s1
,
err
:=
h2
.
NewStream
(
ctx
,
h1
.
ID
(),
FloodSubID
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
time
.
Sleep
(
100
*
time
.
Millisecond
)
s2
,
err
:=
h2
.
NewStream
(
ctx
,
h1
.
ID
(),
FloodSubID
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
time
.
Sleep
(
100
*
time
.
Millisecond
)
s3
,
err
:=
h2
.
NewStream
(
ctx
,
h1
.
ID
(),
FloodSubID
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
time
.
Sleep
(
100
*
time
.
Millisecond
)
// check that s1 and s2 have been reset
_
,
err
=
s1
.
Read
([]
byte
{
0
})
if
err
==
nil
{
t
.
Fatal
(
"expected s1 to be reset"
)
}
_
,
err
=
s2
.
Read
([]
byte
{
0
})
if
err
==
nil
{
t
.
Fatal
(
"expected s2 to be reset"
)
}
// check that s3 is readable and simply times out
s3
.
SetReadDeadline
(
time
.
Now
()
.
Add
(
time
.
Millisecond
))
_
,
err
=
s3
.
Read
([]
byte
{
0
})
err2
,
ok
:=
err
.
(
interface
{
Timeout
()
bool
})
if
!
ok
||
!
err2
.
Timeout
()
{
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