Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
0045b444
Commit
0045b444
authored
Dec 12, 2016
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
8ab1e541
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
23 deletions
+57
-23
t/neo/connection_test.go
t/neo/connection_test.go
+57
-23
No files found.
t/neo/connection_test.go
View file @
0045b444
...
...
@@ -102,6 +102,17 @@ func xwait(t *testing.T, w interface { Wait() error }) {
}
}
// Prepare PktBuf with content
func
mkpkt
(
msgid
uint32
,
msgcode
uint16
,
payload
[]
byte
)
*
PktBuf
{
pkt
:=
&
PktBuf
{
make
([]
byte
,
PktHeadLen
+
len
(
payload
))}
pkth
:=
pkt
.
Header
()
pkth
.
MsgId
=
hton32
(
msgid
)
pkth
.
MsgCode
=
hton16
(
msgcode
)
pkth
.
Len
=
hton32
(
PktHeadLen
+
4
)
copy
(
pkt
.
Payload
(),
payload
)
return
pkt
}
// delay a bit
// needed e.g. to test Close interaction with waiting read or write
// (we cannot easily sync and make sure e.g. read is started and became asleep)
...
...
@@ -152,23 +163,12 @@ func TestNodeLink(t *testing.T) {
// * wait all for finish
// * rethrough in main
nl1
,
nl2
=
nodeLinkPipe
()
g
,
ctx
:=
errgroup
.
WithContext
(
context
.
Background
())
// XXX move vvv also to g ?
go
func
()
{
<-
ctx
.
Done
()
//time.Sleep(100*time.Millisecond)
t
.
Log
(
"ctx was Done - closing nodelinks"
)
nl1
.
Close
()
// XXX err
nl2
.
Close
()
// XXX err
}()
// check raw exchange works
g
,
ctx
:=
errgroup
.
WithContext
(
context
.
Background
())
g
.
Go
(
func
()
error
{
// send ping; wait for pong
pkt
:=
&
PktBuf
{
make
([]
byte
,
PktHeadLen
+
4
)}
pkth
:=
pkt
.
Header
()
pkth
.
Len
=
hton32
(
PktHeadLen
+
4
)
copy
(
pkt
.
Payload
(),
"ping"
)
pkt
:=
mkpkt
(
1
,
2
,
[]
byte
(
"ping"
))
err
:=
nl1
.
sendPkt
(
pkt
)
if
err
!=
nil
{
t
.
Errorf
(
"nl1.sendPkt: %v"
,
err
)
...
...
@@ -179,7 +179,8 @@ func TestNodeLink(t *testing.T) {
t
.
Errorf
(
"nl1.recvPkt: %v"
,
err
)
return
err
}
if
!
bytes
.
Equal
(
pkt
.
Data
,
[]
byte
(
"pong"
))
{
// TODO vvv also check msgid, msgcode
if
!
bytes
.
Equal
(
pkt
.
Payload
(),
[]
byte
(
"pong"
))
{
// XXX vvv -> util ?
e
:=
fmt
.
Errorf
(
"nl1 received: %v ; want
\"
pong
\"
"
,
pkt
.
Data
)
t
.
Error
(
e
)
...
...
@@ -194,13 +195,14 @@ func TestNodeLink(t *testing.T) {
t
.
Errorf
(
"nl2.recvPkt: %v"
,
err
)
return
err
}
if
!
bytes
.
Equal
(
pkt
.
Data
,
[]
byte
(
"ping"
))
{
// TODO vvv also check msgid, msgcode
if
!
bytes
.
Equal
(
pkt
.
Payload
(),
[]
byte
(
"ping"
))
{
// XXX vvv -> util ?
e
:=
fmt
.
Errorf
(
"nl2 received: %v ; want
\"
ping
\"
"
,
pkt
.
Data
)
t
.
Error
(
e
)
return
e
}
pkt
=
&
PktBuf
{[]
byte
(
"pong"
)}
pkt
=
mkpkt
(
3
,
4
,
[]
byte
(
"pong"
))
err
=
nl2
.
sendPkt
(
pkt
)
if
err
!=
nil
{
t
.
Errorf
(
"nl2.sendPkt: %v"
,
err
)
...
...
@@ -209,14 +211,46 @@ func TestNodeLink(t *testing.T) {
return
nil
})
xwait
(
t
,
g
)
t
.
Fatal
(
"bbb"
)
g2
:=
&
errgroup
.
Group
{}
g2
.
Go
(
func
()
error
{
<-
ctx
.
Done
()
ev
:=
xerror
.
Errorv
{}
ev
.
addif
(
nl1
.
Close
()
)
ev
.
addif
(
nl2
.
Close
()
)
return
ev
.
Reduce
()
// nil if len==0; [0] if len==1; [...] otherwise
/*
err = g.Wait()
for c := range []io.Closer{nl1, nl2} {
err := c.Close()
if err != nil {
t.Fatal("raw exchange verification failed")
ev = append(ev, err)
}
}
*/
/*
err := nl1.Close()
err2 := nl2.Close()
if err == nil {
err = err2
}
*/
})
xwait
(
g
)
xwait
(
g2
)
// close nodelinks either when checks are done, or upon first error
closed
:=
make
(
chan
struct
{})
go
func
()
{
<-
ctx
.
Done
()
nl1
.
Close
()
// XXX err
nl2
.
Close
()
// XXX err
close
(
closed
)
}()
xwait
(
t
,
g
)
<-
closed
/*
// test 1 channels on top of nodelink
...
...
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