Skip to content

Commit

Permalink
add close connection on telemetry unmarshal error unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
QxBytes committed Apr 26, 2024
1 parent 43c16e1 commit e8447f9
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions telemetry/telemetrybuffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,30 @@ func TestClientConnClose(t *testing.T) {
tbClient.Close()
}

func TestCloseOnWriteError(t *testing.T) {
tbServer, closeTBServer := createTBServer(t)
defer closeTBServer()

tbClient := NewTelemetryBuffer(nil)
err := tbClient.Connect()
require.NoError(t, err)
defer tbClient.Close()

data := []byte("{\"good\":1}")
_, err = tbClient.Write(data)
require.NoError(t, err)
// need to wait for connection to populate in server
time.Sleep(1 * time.Second)
require.Len(t, tbServer.connections, 1)

// the connection should be automatically closed on failure
badData := []byte("} malformed json }}}")
_, err = tbClient.Write(badData)
require.NoError(t, err)
time.Sleep(1 * time.Second)
require.Empty(t, tbServer.connections)
}

func TestWrite(t *testing.T) {
_, closeTBServer := createTBServer(t)
defer closeTBServer()
Expand Down

0 comments on commit e8447f9

Please sign in to comment.