Skip to content

Commit 3c3c567

Browse files
[8.19] Improve rolling appender test logic (#242095) (#242260)
# Backport This will backport the following commits from `main` to `8.19`: - [Improve rolling appender test logic (#242095)](#242095) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Gerard Soldevila","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-11-07T13:27:52Z","message":"Improve rolling appender test logic (#242095)\n\n## Summary\n\nCloses https://github.com/elastic/kibana/issues/232893\n\nThe previous improvements were not enough, [latest\nfailure](https://buildkite.com/elastic/kibana-on-merge/builds/81112/steps/canvas?jid=019a4a9c-77de-450f-a4e8-70d4efc34012)\nshows that we can't guarantee how many times the rolling logic has run:\n\n<img width=\"846\" height=\"272\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/9ccaac11-92bb-42cf-8b5a-60fd258c23d9\"\n/>\n\nThe PR makes the test even more resilient by not assuming that the\nrolling logid has run exactly twice, and instead it just makes\nassertions that are valid for the 2 scenarios:\n* Assert there are multiple log files (rollover has happened).\n* Assert that the rolled files are not empty\n* Assert that when concatenating all log files in an ordered fashion, no\nlog entries are lost.","sha":"11a9589ea8068a734dcd0eb9845d462ab73330e2","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Core","release_note:skip","test-failure-flaky","backport:all-open","v9.3.0"],"title":"Improve rolling appender test logic","number":242095,"url":"https://github.com/elastic/kibana/pull/242095","mergeCommit":{"message":"Improve rolling appender test logic (#242095)\n\n## Summary\n\nCloses https://github.com/elastic/kibana/issues/232893\n\nThe previous improvements were not enough, [latest\nfailure](https://buildkite.com/elastic/kibana-on-merge/builds/81112/steps/canvas?jid=019a4a9c-77de-450f-a4e8-70d4efc34012)\nshows that we can't guarantee how many times the rolling logic has run:\n\n<img width=\"846\" height=\"272\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/9ccaac11-92bb-42cf-8b5a-60fd258c23d9\"\n/>\n\nThe PR makes the test even more resilient by not assuming that the\nrolling logid has run exactly twice, and instead it just makes\nassertions that are valid for the 2 scenarios:\n* Assert there are multiple log files (rollover has happened).\n* Assert that the rolled files are not empty\n* Assert that when concatenating all log files in an ordered fashion, no\nlog entries are lost.","sha":"11a9589ea8068a734dcd0eb9845d462ab73330e2"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/242095","number":242095,"mergeCommit":{"message":"Improve rolling appender test logic (#242095)\n\n## Summary\n\nCloses https://github.com/elastic/kibana/issues/232893\n\nThe previous improvements were not enough, [latest\nfailure](https://buildkite.com/elastic/kibana-on-merge/builds/81112/steps/canvas?jid=019a4a9c-77de-450f-a4e8-70d4efc34012)\nshows that we can't guarantee how many times the rolling logic has run:\n\n<img width=\"846\" height=\"272\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/9ccaac11-92bb-42cf-8b5a-60fd258c23d9\"\n/>\n\nThe PR makes the test even more resilient by not assuming that the\nrolling logid has run exactly twice, and instead it just makes\nassertions that are valid for the 2 scenarios:\n* Assert there are multiple log files (rollover has happened).\n* Assert that the rolled files are not empty\n* Assert that when concatenating all log files in an ordered fashion, no\nlog entries are lost.","sha":"11a9589ea8068a734dcd0eb9845d462ab73330e2"}}]}] BACKPORT--> Co-authored-by: Gerard Soldevila <[email protected]>
1 parent cc8d592 commit 3c3c567

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/core/server/integration_tests/logging/rolling_file_appender.test.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -307,22 +307,30 @@ describe('RollingFileAppender', () => {
307307
logger.info(message(5));
308308
logger.info(message(6));
309309

310+
await waitForNextRollingTime();
311+
310312
await flush();
311313

312314
const files = await readdir(testDir);
313315

314-
const sortedLogFiles = files.sort();
315-
expect(sortedLogFiles).toEqual(['kibana-1.log', 'kibana-2.log', 'kibana.log']);
316+
// ['kibana.log', ['kibana-3.log',] 'kibana-2.log', 'kibana-1.log']
317+
const sortedLogFiles = files.sort().reverse();
318+
expect(sortedLogFiles).toContain('kibana.log');
319+
// there could be a kibana-3.log already, but we cannot guarantee it
320+
expect(sortedLogFiles).toContain('kibana-2.log');
321+
expect(sortedLogFiles).toContain('kibana-1.log');
322+
323+
// kibana.log contains the newest entries, so it must go in the end
324+
const kibanaLog = sortedLogFiles.shift()!;
325+
sortedLogFiles.push(kibanaLog);
316326

317327
// the "rolling time sync" mechanism above is not perfect, so the test is going to guarantee:
318-
// - that something has been rolled over
319-
// - that no log entries have been lost
320-
const oldestEntries = await getFileContent('kibana-2.log');
321-
const newerEntries = await getFileContent('kibana-1.log');
322-
const newestEntries = await getFileContent('kibana.log');
323-
const allEntries = oldestEntries + newerEntries + newestEntries;
324-
expect(oldestEntries.length + newerEntries.length).toBeGreaterThan(40);
325-
expect(allEntries).toEqual(expectedFileContent([1, 2, 3, 4, 5, 6]));
328+
// A) that no log entries have been lost
329+
const allEntries = await Promise.all(sortedLogFiles.map(getFileContent));
330+
expect(allEntries.join('')).toEqual(expectedFileContent([1, 2, 3, 4, 5, 6]));
331+
332+
// B) that something has been rolled over
333+
expect(allEntries.slice(-2).join('').length).toBeGreaterThan(40);
326334
});
327335
});
328336
});

0 commit comments

Comments
 (0)