From 9ac329d7e729e44da9f1acd5f4e613314e87f845 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Sun, 15 Oct 2023 13:18:48 +0200 Subject: [PATCH] Add test for Reconnect Fix tests --- network/client_test.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/network/client_test.go b/network/client_test.go index ed431883..8896415e 100644 --- a/network/client_test.go +++ b/network/client_test.go @@ -49,7 +49,7 @@ func TestNewClient(t *testing.T) { assert.Equal(t, "tcp", client.Network) assert.Equal(t, "127.0.0.1:5432", client.Address) assert.NotEmpty(t, client.ID) - assert.NotNil(t, client.Conn) + assert.NotNil(t, client.conn) } // TestSend tests the Send function. @@ -96,7 +96,7 @@ func TestClose(t *testing.T) { assert.Equal(t, "", client.ID) assert.Equal(t, "", client.Network) assert.Equal(t, "", client.Address) - assert.Nil(t, client.Conn) + assert.Nil(t, client.conn) } // TestIsConnected tests the IsConnected function. @@ -108,6 +108,24 @@ func TestIsConnected(t *testing.T) { assert.False(t, client.IsConnected()) } +func TestReconnect(t *testing.T) { + client := CreateNewClient(t) + defer client.Close() + + assert.NotNil(t, client) + assert.NotNil(t, client.conn) + assert.NotEmpty(t, client.ID) + localAddr := client.LocalAddr() + assert.NotEmpty(t, localAddr) + + assert.NoError(t, client.Reconnect()) + assert.NotNil(t, client) + assert.NotNil(t, client.conn) + assert.NotEmpty(t, client.ID) + assert.NotEmpty(t, client.LocalAddr()) + assert.NotEqual(t, localAddr, client.LocalAddr()) // This is a new connection. +} + func BenchmarkNewClient(b *testing.B) { cfg := logging.LoggerConfig{ Output: []config.LogOutput{config.Console},