Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Tiago Queiroz <[email protected]>
  • Loading branch information
emmanueltouzery and belimawr committed May 22, 2024
1 parent 10e920d commit 989fc42
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Removed deprecated Sophos UTM from Beats. Use the https://docs.elastic.co/integrations/sophos[Sophos] Elastic integration instead. {pull}38037[38037]
- Introduce input/netmetrics and refactor netflow input metrics {pull}38055[38055]
- Update Salesforce module to use new Salesforce input. {pull}37509[37509]
- Fix high IO and disrupted operation after sudden filebeat stop. {pull}35893[35893]
- Fix high IO and handling of a corrupted registry log file. {pull}35893[35893]

*Heartbeat*

Expand Down
23 changes: 12 additions & 11 deletions libbeat/statestore/backend/memlog/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,18 @@ package memlog

import (
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/elastic/elastic-agent-libs/logp"
"github.com/elastic/elastic-agent-libs/mapstr"
)

func init() {
logp.DevelopmentSetup()
}

func TestRecoverFromCorruption(t *testing.T) {
path := t.TempDir()
defer os.RemoveAll(path)
logp.DevelopmentSetup()

if err := copyPath(path, "testdata/1/logfile_incomplete/"); err != nil {
t.Fatalf("Failed to copy test file to the temporary directory: %v", err)
Expand All @@ -42,13 +39,17 @@ func TestRecoverFromCorruption(t *testing.T) {
store, err := openStore(logp.NewLogger("test"), path, 0660, 4096, false, func(_ uint64) bool {
return false
})
assert.NoError(t, err)

assert.Equal(t, true, store.disk.logInvalid)
require.NoError(t, err, "openStore must succeed")
require.True(t, store.disk.logInvalid, "expecting the log file to be invalid")

err = store.logOperation(&opSet{K: "key", V: mapstr.M{
"field": 42,
}})
assert.NoError(t, err)
assert.Equal(t, false, store.disk.logInvalid)
require.NoError(t, err, "logOperation must succeed")
require.Equal(t, false, store.disk.logInvalid, "log file must be valid")
require.FileExistsf(t, filepath.Join(path, "7.json"), "expecting the checkpoint file to have been created")

file, err := os.Stat(filepath.Join(path, "log.json"))
require.NoError(t, err, "Stat on the log file must succeed")
require.Equal(t, int64(0), file.Size(), "expecting the log file to be truncated")
}

0 comments on commit 989fc42

Please sign in to comment.