Skip to content

Commit

Permalink
Add test for Reconnect
Browse files Browse the repository at this point in the history
Fix tests
  • Loading branch information
mostafa committed Oct 15, 2023
1 parent e549e58 commit 9ac329d
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions network/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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},
Expand Down

0 comments on commit 9ac329d

Please sign in to comment.