[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() {
|
||||
for _, c := range conn.clients {
|
||||
err := 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)
|
||||
c.Close()
|
||||
}
|
||||
conn.listener.Close()
|
||||
}
|
||||
|
|
|
@ -42,25 +42,31 @@ func TestClient(t *testing.T) {
|
|||
|
||||
config["enable"] = true
|
||||
config["type"] = "unix"
|
||||
config["address"] = "/tmp/yanic-database.socket"
|
||||
config["address"] = "/tmp/yanic-database2.socket"
|
||||
|
||||
conn, err := Connect(config)
|
||||
assert.NoError(err, "connection should work")
|
||||
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.NotNil(client)
|
||||
time.Sleep(1)
|
||||
time.Sleep(time.Duration(3) * time.Microsecond)
|
||||
|
||||
conn.InsertNode(&runtime.Node{})
|
||||
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()
|
||||
assert.NoError(err, "disconnect should work")
|
||||
time.Sleep(1)
|
||||
time.Sleep(time.Duration(3) * time.Microsecond)
|
||||
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()
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package socket
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net"
|
||||
)
|
||||
|
||||
|
@ -15,7 +14,6 @@ func (config *Connection) handleSocketConnection(ln net.Listener) {
|
|||
for {
|
||||
c, err := ln.Accept()
|
||||
if err != nil {
|
||||
log.Println("[socket-database] error during connection of a client", err)
|
||||
continue
|
||||
}
|
||||
config.clients[c.RemoteAddr()] = c
|
||||
|
@ -28,10 +26,7 @@ func (conn *Connection) sendJSON(msg EventMessage) {
|
|||
|
||||
err := d.Encode(&msg)
|
||||
if err != nil {
|
||||
err = c.Close()
|
||||
if err != nil {
|
||||
log.Println("[socket-database] connection could not close after error on sending event:", err)
|
||||
}
|
||||
c.Close()
|
||||
delete(conn.clients, i)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue