Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
c5940f2e
Commit
c5940f2e
authored
Dec 12, 2016
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
98441d38
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
8 deletions
+60
-8
t/neo/connection.go
t/neo/connection.go
+3
-4
t/neo/connection_test.go
t/neo/connection_test.go
+57
-4
No files found.
t/neo/connection.go
View file @
c5940f2e
...
...
@@ -105,7 +105,7 @@ func (nl *NodeLink) recvPkt() (pkt *PktBuf, err error) {
rxbuf
:=
make
([]
byte
,
4096
)
n
,
err
:=
io
.
ReadAtLeast
(
nl
.
peerLink
,
rxbuf
,
PktHeadLen
)
if
err
!=
nil
{
panic
(
err
)
// XXX err
return
nil
,
err
// XXX err adjust ?
}
pkth
:=
pkt
.
Header
()
...
...
@@ -187,10 +187,9 @@ func (nl *NodeLink) HandleNewConn(h func(*Conn)) {
// Close node-node link.
// IO on connections established over it is automatically interrupted with an error.
// XXX ^^^ recheck
func
(
nl
*
NodeLink
)
Close
()
error
{
// TODO
return
n
il
// TODO
adjust connTab & friends
return
n
l
.
peerLink
.
Close
()
}
...
...
t/neo/connection_test.go
View file @
c5940f2e
...
...
@@ -15,21 +15,27 @@
package
neo
import
(
//"fmt"
"io"
"net"
"testing"
"time"
)
func
xsend
(
c
*
Conn
,
pkt
*
PktBuf
)
{
err
:=
c
.
Send
(
pkt
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
// XXX make sure this happens in main goroutine
//t.Fatal(err) // XXX make sure this happens in main goroutine
panic
(
"TODO"
)
}
}
func
xrecv
(
c
*
Conn
)
*
PktBuf
{
pkt
,
err
:=
c
.
Recv
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
// XXX make sure this happens in main goroutine
//t.Fatal(err) // XXX make sure this happens in main goroutine
panic
(
"TODO"
)
}
return
pkt
}
...
...
@@ -39,7 +45,6 @@ func xsendPkt(nl *NodeLink, pkt *PktBuf) {
if
err
!=
nil
{
panic
(
"TODO"
)
}
return
err
}
func
xrecvPkt
(
nl
*
NodeLink
)
*
PktBuf
{
...
...
@@ -50,6 +55,7 @@ func xrecvPkt(nl *NodeLink) *PktBuf {
return
pkt
}
/*
func xspawn(funcv ...func()) {
for f := range funcv {
go func() {
...
...
@@ -62,13 +68,59 @@ func xspawn(funcv ...func()) {
}
}
}
*/
// run f in a goroutine, see its return error, if != nil -> t.Fatal in main goroutine
func
xgo
(
t
*
testing
.
T
,
f
func
()
error
)
{
var
err
error
done
:=
make
(
chan
struct
{})
go
func
()
{
err
=
f
()
close
(
done
)
}()
<-
done
if
err
!=
nil
{
t
.
Fatal
(
err
)
// TODO adjust lineno (report not here)
}
}
// 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)
func
tdelay
()
{
time
.
Sleep
(
1
*
time
.
Millisecond
)
}
func
TestNodeLink
(
t
*
testing
.
T
)
{
//
TODO
verify NodeLink via net.Pipe
// verify NodeLink via net.Pipe
node1
,
node2
:=
net
.
Pipe
()
nl1
:=
NewNodeLink
(
node1
)
nl2
:=
NewNodeLink
(
node2
)
// Close vs recv
xgo
(
t
,
func
()
error
{
tdelay
()
return
nl1
.
Close
()
})
pkt
,
err
:=
nl1
.
recvPkt
()
if
!
(
pkt
==
nil
&&
err
==
io
.
ErrClosedPipe
)
{
t
.
Fatalf
(
"NodeLink.recvPkt() after close: pkt = %v err = %v"
,
pkt
,
err
)
}
// Close vs send
xgo
(
t
,
func
()
error
{
tdelay
()
return
nl2
.
Close
()
})
pkt
=
&
PktBuf
{[]
byte
(
"hello world"
)}
err
=
nl2
.
sendPkt
(
pkt
)
if
err
!=
io
.
ErrClosedPipe
{
t
.
Fatalf
(
"NodeLink.sendPkt() after close: err = %v"
,
err
)
}
/*
// TODO setup context
// TODO on context.cancel -> nl{1,2} -> Close
// TODO every func: run with exception catcher (including t.Fatal)
...
...
@@ -104,6 +156,7 @@ func TestNodeLink(t *testing.T) {
t.Fatal(...) // XXX bad in goroutine
}
}
*/
/*
// 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