Commit 98441d38 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 3ca87f70
...@@ -19,40 +19,91 @@ import ( ...@@ -19,40 +19,91 @@ import (
"testing" "testing"
) )
func xsend(c *Conn, pkt PktBuf) { func xsend(c *Conn, pkt *PktBuf) {
err := c.Send(pkt) err := c.Send(pkt)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err) // XXX make sure this happens in main goroutine
} }
} }
func xrecv(c *Conn) PktBuf { func xrecv(c *Conn) *PktBuf {
pkt, err := c.Recv() pkt, err := c.Recv()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err) // XXX make sure this happens in main goroutine
} }
return pkt return pkt
} }
func xsendPkt(nl *NodeLink, pkt *PktBuf) {
err := nl.sendPkt(pkt)
if err != nil {
panic("TODO")
}
return err
}
func xrecvPkt(nl *NodeLink) *PktBuf {
pkt, err := nl.recvPkt()
if err != nil {
panic("TODO")
}
return pkt
}
func xspawn(funcv ...func()) {
for f := range funcv {
go func() {
defer func() {
e := recover()
if e == nil {
return
}
}
}
}
}
func TestNodeLink(t *testing.T) { func TestNodeLink(t *testing.T) {
// TODO verify NodeLink via net.Pipe // TODO verify NodeLink via net.Pipe
node1, node2 := net.Pipe() node1, node2 := net.Pipe()
nl1 := NewNodeLink(node1) nl1 := NewNodeLink(node1)
nl2 := NewNodeLink(node2) nl2 := NewNodeLink(node2)
// TODO setup context
// TODO on context.cancel -> nl{1,2} -> Close
// TODO every func: run with exception catcher (including t.Fatal)
// if caught:
// * ctx.cancel
// * wait all for finish
// * rethrough in main
// first check raw exchange works // first check raw exchange works
go func() { go func() {
err := nl1.sendPkt(...) pkt = ...
err := nl1.sendPkt(pkt)
if err != nil { if err != nil {
t.Fatal(...) // XXX bad in goroutine t.Fatal(...) // XXX bad in goroutine
} }
pkt, err = nl1.recvPkt()
if err != nil {
t.Fatal(...)
}
// TODO check pkt == what was sent back
}() }()
pkt, err := nl2.recvPkt(...) go func() {
if err != nil { pkt, err := nl2.recvPkt()
t.Fatal(...) if err != nil {
t.Fatal(...)
}
// TODO check pkt == what was sent
// TODO change pkt a bit
// send pkt back
err = nl2.sendPkt(pkt)
if err != nil {
t.Fatal(...) // XXX bad in goroutine
}
} }
// TODO check pkt == what was sent
// TODO also check ^^^ in opposite direction
/* /*
// test 1 channels on top of nodelink // test 1 channels on top of nodelink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment