Commit d29c0d3b authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 2d85f4aa
...@@ -161,7 +161,7 @@ func (nl *NodeLink) Close() error { ...@@ -161,7 +161,7 @@ func (nl *NodeLink) Close() error {
// send raw packet to peer // send raw packet to peer
func (nl *NodeLink) sendPkt(pkt *PktBuf) error { func (nl *NodeLink) sendPkt(pkt *PktBuf) error {
_, err := nl.peerLink.Write(pkt.Data) _, err := nl.peerLink.Write(pkt.Data) // FIXME write Data in full
if err != nil { if err != nil {
// XXX do we need to retry if err is temporary? // XXX do we need to retry if err is temporary?
// TODO data could be written partially and thus the message stream is now broken // TODO data could be written partially and thus the message stream is now broken
......
...@@ -142,14 +142,31 @@ func nodeLinkPipe() (nl1, nl2 *NodeLink) { ...@@ -142,14 +142,31 @@ func nodeLinkPipe() (nl1, nl2 *NodeLink) {
return _nodeLinkPipe(0) return _nodeLinkPipe(0)
} }
func TestPipe(t *testing.T) {
p1, p2 := net.Pipe()
wg := WorkGroup()
wg.Gox(func() {
tdelay()
println("aaa")
xclose(p1)
println("bbb")
})
println("111")
_, err := p1.Write([]byte("data"))
println("222")
if err != io.ErrClosedPipe {
t.Fatalf("unexpected err = %v", err)
}
xwait(wg)
xclose(p2)
}
func TestNodeLink(t *testing.T) { func TestNodeLink(t *testing.T) {
// TODO catch exception -> add proper location from it -> t.Fatal (see git-backup) // TODO catch exception -> add proper location from it -> t.Fatal (see git-backup)
nl1, nl2 := nodeLinkPipe()
// Close vs recvPkt // Close vs recvPkt
println("111") println("111")
nl1, nl2 := _nodeLinkPipe(connNoRecvSend)
wg := WorkGroup() wg := WorkGroup()
wg.Gox(func() { wg.Gox(func() {
tdelay() tdelay()
...@@ -160,20 +177,28 @@ func TestNodeLink(t *testing.T) { ...@@ -160,20 +177,28 @@ func TestNodeLink(t *testing.T) {
t.Fatalf("NodeLink.recvPkt() after close: pkt = %v err = %v", pkt, err) t.Fatalf("NodeLink.recvPkt() after close: pkt = %v err = %v", pkt, err)
} }
xwait(wg) xwait(wg)
xclose(nl2)
// Close vs sendPkt // Close vs sendPkt
println("222") println("222")
nl1, nl2 = _nodeLinkPipe(connNoRecvSend)
wg = WorkGroup() wg = WorkGroup()
wg.Gox(func() { wg.Gox(func() {
tdelay() tdelay()
xclose(nl2) println("close(nl1) aaa")
xclose(nl1)
println("close(nl1) bbb")
}) })
pkt = &PktBuf{[]byte("data")} pkt = &PktBuf{[]byte("data")}
err = nl2.sendPkt(pkt) println("zzz")
err = nl1.sendPkt(pkt)
println("qqq")
if err != io.ErrClosedPipe { if err != io.ErrClosedPipe {
t.Fatalf("NodeLink.sendPkt() after close: err = %v", err) t.Fatalf("NodeLink.sendPkt() after close: err = %v", err)
} }
xwait(wg) xwait(wg)
xclose(nl2)
return
// check raw exchange works // check raw exchange works
println("333") println("333")
......
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