Commit 3b5bb769 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 8a8ddf1e
...@@ -92,6 +92,7 @@ type Conn struct { ...@@ -92,6 +92,7 @@ type Conn struct {
} }
// XXX include actual op (read/write/accept/connect) when there is an error ?
var ErrLinkClosed = errors.New("node link is closed") // operations on closed NodeLink var ErrLinkClosed = errors.New("node link is closed") // operations on closed NodeLink
var ErrLinkDown = errors.New("node link is down") // e.g. due to IO error var ErrLinkDown = errors.New("node link is down") // e.g. due to IO error
var ErrLinkNoListen = errors.New("node link is not listening for incoming connections") var ErrLinkNoListen = errors.New("node link is not listening for incoming connections")
...@@ -254,9 +255,9 @@ func (nl *NodeLink) Accept() (*Conn, error) { ...@@ -254,9 +255,9 @@ func (nl *NodeLink) Accept() (*Conn, error) {
select { select {
case <-nl.down: case <-nl.down:
if atomic.LoadUint32(&nl.closed) != 0 { if atomic.LoadUint32(&nl.closed) != 0 {
return nil, ErrLinkClosed // XXX + op = Accept ? return nil, ErrLinkClosed
} }
return nil, ErrLinkDown // XXX test return nil, ErrLinkDown
case c := <-nl.acceptq: case c := <-nl.acceptq:
return c, nil return c, nil
......
...@@ -355,16 +355,28 @@ func TestNodeLink(t *testing.T) { ...@@ -355,16 +355,28 @@ func TestNodeLink(t *testing.T) {
} }
}) })
wg.Gox(func() {
conn, err := nl2.Accept()
if !(conn == nil && err == ErrLinkDown) {
exc.Raisef("Accept after peer NodeLink shutdown: conn = %v err = %v", conn, err)
}
})
tdelay() tdelay()
xclose(nl1) xclose(nl1)
xwait(wg) xwait(wg)
// XXX denoise vvv // XXX denoise vvv
// NewConn after NodeLink stop // NewConn after NodeLink shutdown
c, err = nl2.NewConn() c, err = nl2.NewConn()
if err != ErrLinkDown { if err != ErrLinkDown {
t.Fatalf("NewConn after NodeLink stop: %v", err) t.Fatalf("NewConn after NodeLink shutdown: %v", err)
}
// Accept after NodeLink shutdown
c, err = nl2.Accept()
if err != ErrLinkDown {
t.Fatalf("Accept after NodeLink shutdown: conn = %v err = %v", c, err)
} }
// Recv/Send on another Conn // Recv/Send on another Conn
...@@ -380,11 +392,11 @@ func TestNodeLink(t *testing.T) { ...@@ -380,11 +392,11 @@ func TestNodeLink(t *testing.T) {
// Recv/Send error on second call // Recv/Send error on second call
pkt, err = c21.Recv() pkt, err = c21.Recv()
if !(pkt == nil && err == ErrLinkDown) { if !(pkt == nil && err == ErrLinkDown) {
t.Fatalf("Conn.Recv after NodeLink stop: pkt = %v err = %v", pkt, err) t.Fatalf("Conn.Recv after NodeLink shutdown: pkt = %v err = %v", pkt, err)
} }
err = c22.Send(&PktBuf{[]byte("data")}) err = c22.Send(&PktBuf{[]byte("data")})
if err != ErrLinkDown { if err != ErrLinkDown {
t.Fatalf("Conn.Send after NodeLink stop: %v", err) t.Fatalf("Conn.Send after NodeLink shutdown: %v", err)
} }
xclose(c23) xclose(c23)
...@@ -399,21 +411,25 @@ func TestNodeLink(t *testing.T) { ...@@ -399,21 +411,25 @@ func TestNodeLink(t *testing.T) {
} }
xclose(nl2) xclose(nl2)
// Recv/Send error after NodeLink close // Recv/Send NewConn/Accept error after NodeLink close
pkt, err = c21.Recv() pkt, err = c21.Recv()
if !(pkt == nil && err == ErrLinkClosed) { if !(pkt == nil && err == ErrLinkClosed) {
t.Fatalf("Conn.Recv after NodeLink stop: pkt = %v err = %v", pkt, err) t.Fatalf("Conn.Recv after NodeLink shutdown: pkt = %v err = %v", pkt, err)
} }
err = c22.Send(&PktBuf{[]byte("data")}) err = c22.Send(&PktBuf{[]byte("data")})
if err != ErrLinkClosed { if err != ErrLinkClosed {
t.Fatalf("Conn.Send after NodeLink stop: %v", err) t.Fatalf("Conn.Send after NodeLink shutdown: %v", err)
} }
// NewConn after NodeLink close
c, err = nl2.NewConn() c, err = nl2.NewConn()
if err != ErrLinkClosed { if err != ErrLinkClosed {
t.Fatalf("NewConn after NodeLink close: %v", err) t.Fatalf("NewConn after NodeLink close: %v", err)
} }
c, err = nl2.Accept()
if err != ErrLinkClosed {
t.Fatalf("Accept after NodeLink close: %v", err)
}
xclose(c21) xclose(c21)
xclose(c22) xclose(c22)
......
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