From 73219323cf8e211e115bed05a035a466cbdd3908 Mon Sep 17 00:00:00 2001 From: Martin Geno Date: Thu, 27 Apr 2017 21:45:44 +0200 Subject: [PATCH] [TASK] remove unreachable logs --- database/socket/database.go | 10 ++-------- database/socket/database_test.go | 16 +++++++++++----- database/socket/internal.go | 7 +------ 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/database/socket/database.go b/database/socket/database.go index baf9735..afd525c 100644 --- a/database/socket/database.go +++ b/database/socket/database.go @@ -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() } diff --git a/database/socket/database_test.go b/database/socket/database_test.go index 8af6bb4..562ee4b 100644 --- a/database/socket/database_test.go +++ b/database/socket/database_test.go @@ -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() } diff --git a/database/socket/internal.go b/database/socket/internal.go index 6f827c7..7984e5d 100644 --- a/database/socket/internal.go +++ b/database/socket/internal.go @@ -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) } }