Skip to content

Commit

Permalink
remove test since it gets affected by global state
Browse files Browse the repository at this point in the history
  • Loading branch information
mauri870 committed Dec 13, 2024
1 parent 9c04783 commit 95062d9
Showing 1 changed file with 0 additions and 71 deletions.
71 changes: 0 additions & 71 deletions libbeat/reader/multiline/message_buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest/observer"

"github.com/elastic/beats/v7/libbeat/reader"
"github.com/elastic/elastic-agent-libs/logp"
"github.com/elastic/elastic-agent-libs/mapstr"
)

Expand Down Expand Up @@ -138,74 +135,6 @@ func TestFinalizeMessage(t *testing.T) {

}

func TestLogTruncatedMessage(t *testing.T) {
tests := []struct {
name string
msgFunc func()
assertFunc func(t *testing.T, logs []observer.LoggedEntry)
}{
{
name: "truncated",
msgFunc: func() {
msgs := []reader.Message{
{Content: []byte("line1\nline2\nline3"), Bytes: 15},
}

getTestMessageBuffer(10, false, msgs).finalize()
},
assertFunc: func(t *testing.T, logs []observer.LoggedEntry) {
require.Len(t, logs, 1)
assert.Contains(t, logs[0].Message, "The multiline message is too large and has been truncated to the limit of 5 lines or 10 bytes.")
assert.Equal(t, "warn", logs[0].Level.String())
},
},
{
name: "not truncated",
msgFunc: func() {
msgs := []reader.Message{
{Content: []byte("line1\nline2"), Bytes: 15},
}

getTestMessageBuffer(15, false, msgs).finalize()
},
assertFunc: func(t *testing.T, logs []observer.LoggedEntry) {
require.Empty(t, logs)
},
},
{
name: "log messages are rate limited",
msgFunc: func() {
msgs := []reader.Message{
{Content: []byte("line1\nline2\nline3"), Bytes: 10},
}
for i := 0; i < 2000; i++ {
getTestMessageBuffer(10, false, msgs).finalize()
}
},
assertFunc: func(t *testing.T, logs []observer.LoggedEntry) {
// Log happens once every 1000 messages.
require.Len(t, logs, 2)
for _, l := range logs {
assert.Contains(t, l.Message, "The multiline message is too large and has been truncated to the limit of 5 lines or 10 bytes.")
assert.Equal(t, "reader_multiline", l.LoggerName)
assert.Equal(t, "warn", l.Level.String())
}
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
logp.DevelopmentSetup(logp.ToObserverOutput())

tt.msgFunc()

logs := logp.ObserverLogs().TakeAll()
tt.assertFunc(t, logs)
})
}
}

func getTestMessageBuffer(maxBytes int, skipNewline bool, messages []reader.Message) *messageBuffer {
buf := newMessageBuffer(maxBytes, 5, []byte("\n"), skipNewline)
buf.clear()
Expand Down

0 comments on commit 95062d9

Please sign in to comment.