diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index f87dc01bb151..30f8599351db 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -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* diff --git a/libbeat/statestore/backend/memlog/store_test.go b/libbeat/statestore/backend/memlog/store_test.go index 4128228db3c4..6746ec932dbd 100644 --- a/libbeat/statestore/backend/memlog/store_test.go +++ b/libbeat/statestore/backend/memlog/store_test.go @@ -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) @@ -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") }