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
dms3
go-dms3
Commits
fc5b0c29
Commit
fc5b0c29
authored
Oct 19, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
close listeners. + multiconn test
parent
113c44fe
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
0 deletions
+82
-0
net/conn/multiconn_test.go
net/conn/multiconn_test.go
+82
-0
No files found.
net/conn/multiconn_test.go
View file @
fc5b0c29
...
...
@@ -146,11 +146,16 @@ func setupMultiConns(t *testing.T, ctx context.Context) (a, b *MultiConn) {
t
.
Fatal
(
err
)
}
p1l
.
Close
()
p2l
.
Close
()
log
.
Info
(
"did you make multiconns?"
)
return
c1
.
(
*
MultiConn
),
c2
.
(
*
MultiConn
)
}
func
TestMulticonnSend
(
t
*
testing
.
T
)
{
// t.Skip("fooo")
log
.
Info
(
"TestMulticonnSend"
)
ctx
:=
context
.
Background
()
ctxC
,
cancel
:=
context
.
WithCancel
(
ctx
)
...
...
@@ -211,3 +216,80 @@ func TestMulticonnSend(t *testing.T) {
msgsFrom2
.
CheckDone
(
t
)
<-
time
.
After
(
100
*
time
.
Millisecond
)
}
func
TestMulticonnSendUnderlying
(
t
*
testing
.
T
)
{
// t.Skip("fooo")
log
.
Info
(
"TestMulticonnSendUnderlying"
)
ctx
:=
context
.
Background
()
ctxC
,
cancel
:=
context
.
WithCancel
(
ctx
)
c1
,
c2
:=
setupMultiConns
(
t
,
ctx
)
log
.
Info
(
"gen msgs"
)
num
:=
100
msgsFrom1
:=
genMessages
(
num
,
"from p1 to p2"
)
msgsFrom2
:=
genMessages
(
num
,
"from p2 to p1"
)
var
wg
sync
.
WaitGroup
send
:=
func
(
c
*
MultiConn
,
msgs
*
msgMap
)
{
defer
wg
.
Done
()
conns
:=
make
([]
Conn
,
0
,
len
(
c
.
conns
))
for
_
,
c1
:=
range
c
.
conns
{
conns
=
append
(
conns
,
c1
)
}
i
:=
0
for
_
,
m
:=
range
msgs
.
msgs
{
log
.
Info
(
"send: %s"
,
m
.
payload
)
switch
i
%
3
{
case
0
:
conns
[
0
]
.
Out
()
<-
[]
byte
(
m
.
payload
)
case
1
:
conns
[
1
]
.
Out
()
<-
[]
byte
(
m
.
payload
)
case
2
:
c
.
Out
()
<-
[]
byte
(
m
.
payload
)
}
msgs
.
Sent
(
t
,
m
.
payload
)
<-
time
.
After
(
time
.
Microsecond
*
10
)
i
++
}
}
recv
:=
func
(
ctx
context
.
Context
,
c
*
MultiConn
,
msgs
*
msgMap
)
{
defer
wg
.
Done
()
for
{
select
{
case
payload
:=
<-
c
.
In
()
:
msgs
.
Received
(
t
,
string
(
payload
))
log
.
Info
(
"recv: %s"
,
payload
)
if
msgs
.
recv
==
len
(
msgs
.
msgs
)
{
return
}
case
<-
ctx
.
Done
()
:
return
}
}
}
log
.
Info
(
"msg send + recv"
)
wg
.
Add
(
4
)
go
send
(
c1
,
msgsFrom1
)
go
send
(
c2
,
msgsFrom2
)
go
recv
(
ctxC
,
c1
,
msgsFrom2
)
go
recv
(
ctxC
,
c2
,
msgsFrom1
)
wg
.
Wait
()
cancel
()
c1
.
Close
()
c2
.
Close
()
msgsFrom1
.
CheckDone
(
t
)
msgsFrom2
.
CheckDone
(
t
)
}
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