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-reuseport-transport
Commits
d11e3534
Commit
d11e3534
authored
Mar 29, 2018
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add another test case
parent
4d971957
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
1 deletion
+47
-1
transport_test.go
transport_test.go
+47
-1
No files found.
transport_test.go
View file @
d11e3534
package
tcpreuse
import
(
"net"
"testing"
ma
"github.com/multiformats/go-multiaddr"
)
func
Test
All
(
t
*
testing
.
T
)
{
func
Test
Single
(
t
*
testing
.
T
)
{
var
trA
Transport
var
trB
Transport
laddr
,
_
:=
ma
.
NewMultiaddr
(
"/ip4/127.0.0.1/tcp/0"
)
...
...
@@ -38,3 +39,48 @@ func TestAll(t *testing.T) {
<-
done
c
.
Close
()
}
func
TestTwoLocal
(
t
*
testing
.
T
)
{
var
trA
Transport
var
trB
Transport
laddr
,
_
:=
ma
.
NewMultiaddr
(
"/ip4/127.0.0.1/tcp/0"
)
listenerA
,
err
:=
trA
.
Listen
(
laddr
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
listenerA
.
Close
()
listenerB1
,
err
:=
trB
.
Listen
(
laddr
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
listenerB1
.
Close
()
listenerB2
,
err
:=
trB
.
Listen
(
laddr
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
listenerB2
.
Close
()
done
:=
make
(
chan
struct
{})
go
func
()
{
defer
close
(
done
)
c
,
err
:=
listenerA
.
Accept
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
c
.
Close
()
}()
c
,
err
:=
trB
.
Dial
(
listenerA
.
Multiaddr
())
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
localPort
:=
c
.
LocalAddr
()
.
(
*
net
.
TCPAddr
)
.
Port
if
localPort
!=
listenerB1
.
Addr
()
.
(
*
net
.
TCPAddr
)
.
Port
&&
localPort
!=
listenerB2
.
Addr
()
.
(
*
net
.
TCPAddr
)
.
Port
{
t
.
Fatal
(
"didn't dial from one of our listener ports"
)
}
<-
done
c
.
Close
()
}
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