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 f02a31f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func Test_runCmdWithCachePlugin(t *testing.T) {
var waitGroup sync.WaitGroup
waitGroup.Add(1)
go func(waitGroup *sync.WaitGroup) {
time.Sleep(500 * time.Millisecond)
time.Sleep(time.Second)

StopGracefully(
runCmd.Context(),
Expand Down
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 f02a31f

Please sign in to comment.