[TASK] remove unreachable logs
This commit is contained in:
parent
c8cc65e4c4
commit
73219323cf
@ -70,13 +70,7 @@ func (conn *Connection) PruneNodes(deleteAfter time.Duration) {
|
|||||||
|
|
||||||
func (conn *Connection) Close() {
|
func (conn *Connection) Close() {
|
||||||
for _, c := range conn.clients {
|
for _, c := range conn.clients {
|
||||||
err := c.Close()
|
c.Close()
|
||||||
if err != nil {
|
|
||||||
log.Println("[socket-database] client was not able to close:", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
err := conn.listener.Close()
|
|
||||||
if err != nil {
|
|
||||||
log.Println("[socket-database] server was not able to close:", err)
|
|
||||||
}
|
}
|
||||||
|
conn.listener.Close()
|
||||||
}
|
}
|
||||||
|
@ -42,25 +42,31 @@ func TestClient(t *testing.T) {
|
|||||||
|
|
||||||
config["enable"] = true
|
config["enable"] = true
|
||||||
config["type"] = "unix"
|
config["type"] = "unix"
|
||||||
config["address"] = "/tmp/yanic-database.socket"
|
config["address"] = "/tmp/yanic-database2.socket"
|
||||||
|
|
||||||
conn, err := Connect(config)
|
conn, err := Connect(config)
|
||||||
assert.NoError(err, "connection should work")
|
assert.NoError(err, "connection should work")
|
||||||
assert.NotNil(conn)
|
assert.NotNil(conn)
|
||||||
|
|
||||||
client, err := net.Dial("unix", "/tmp/yanic-database.socket")
|
client, err := net.Dial("unix", "/tmp/yanic-database2.socket")
|
||||||
assert.NoError(err, "connection should work")
|
assert.NoError(err, "connection should work")
|
||||||
assert.NotNil(client)
|
assert.NotNil(client)
|
||||||
time.Sleep(1)
|
time.Sleep(time.Duration(3) * time.Microsecond)
|
||||||
|
|
||||||
conn.InsertNode(&runtime.Node{})
|
conn.InsertNode(&runtime.Node{})
|
||||||
conn.InsertGlobals(&runtime.GlobalStats{}, time.Now())
|
conn.InsertGlobals(&runtime.GlobalStats{}, time.Now())
|
||||||
conn.PruneNodes(time.Duration(3))
|
time.Sleep(time.Duration(3) * time.Microsecond)
|
||||||
|
|
||||||
|
// to reach in sendJSON removing of disconnection
|
||||||
err = client.Close()
|
err = client.Close()
|
||||||
assert.NoError(err, "disconnect should work")
|
assert.NoError(err, "disconnect should work")
|
||||||
time.Sleep(1)
|
time.Sleep(time.Duration(3) * time.Microsecond)
|
||||||
conn.InsertNode(&runtime.Node{})
|
conn.InsertNode(&runtime.Node{})
|
||||||
|
time.Sleep(time.Duration(3) * time.Microsecond)
|
||||||
|
|
||||||
|
// to reach all parts of conn.Close()
|
||||||
|
client, err = net.Dial("unix", "/tmp/yanic-database2.socket")
|
||||||
|
time.Sleep(time.Duration(3) * time.Microsecond)
|
||||||
|
|
||||||
conn.Close()
|
conn.Close()
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package socket
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log"
|
|
||||||
"net"
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,7 +14,6 @@ func (config *Connection) handleSocketConnection(ln net.Listener) {
|
|||||||
for {
|
for {
|
||||||
c, err := ln.Accept()
|
c, err := ln.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("[socket-database] error during connection of a client", err)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
config.clients[c.RemoteAddr()] = c
|
config.clients[c.RemoteAddr()] = c
|
||||||
@ -28,10 +26,7 @@ func (conn *Connection) sendJSON(msg EventMessage) {
|
|||||||
|
|
||||||
err := d.Encode(&msg)
|
err := d.Encode(&msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = c.Close()
|
c.Close()
|
||||||
if err != nil {
|
|
||||||
log.Println("[socket-database] connection could not close after error on sending event:", err)
|
|
||||||
}
|
|
||||||
delete(conn.clients, i)
|
delete(conn.clients, i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user