Skip to content

[#356] RotatableWriterTest: list the archives after the rotator stops, keep only the last listing - #361

Merged
vharseko merged 1 commit into
OpenIdentityPlatform:masterfrom
vharseko:issue-356-rotatable-writer-test-listing
Oct 18, 2026
Merged

vharseko merged 1 commit into
OpenIdentityPlatform:masterfrom
vharseko:issue-356-rotatable-writer-test-listing

Conversation

@vharseko

Copy link
Copy Markdown
Member

Summary

RotatableWriterTest.testAutomaticallyEvaluatesPolicesPeriodicallyIfRotationIntervalSpecified listed the archives while the rotator kept rotating the file every second, and getAllHistoricalFiles() added each listing to the previous ones. A listing taken during a rotation holds the renamed file, its .gz archive and the previous archive, which the retention check deletes only after the rotation, so the result never shrank back to one file.

  • The test closes the writer before it lists the archives: close() shuts the rotator down and waits for a running rotation and retention check, so the listing sees the state that retention left.
  • getAllHistoricalFiles() keeps only the last listing instead of accumulating them; the unused existingFiles parameter is gone.

Only the test changes.

Reproduction

A temporary Thread.sleep in GzipUtil.compressRotatedFile(), before the uncompressed file is deleted, widened the rotation window, and the test ran 6 times (invocationCount = 6). Neither of these is part of the PR.

Code Rotation window Result
master 700 ms 6/6 pass: the listing at 3 s misses the rotations
master 1200 ms 6/6 fail with Expected size: 1 but was: 3 (the renamed file, its .gz, the previous .gz) in ~4.3 s, as on CI
helper fix only 1200 ms 6/6 pass
helper fix only 1500 ms 6/6 fail: the last listing still falls into a rotation
helper fix + close() 1500 ms 6/6 pass
helper fix + close() 3000 ms 6/6 pass

Testing

  • mvn -o -pl commons/audit/core -am test: 160 tests, 0 failures.
  • RotatableWriterTest again after the final comment edits: 18 tests, 0 failures.

Fixes #356

…er the rotator stops, keep only the last listing

testAutomaticallyEvaluatesPolicesPeriodicallyIfRotationIntervalSpecified
listed the archives while the rotator kept rotating the file every second.
A listing taken during a rotation holds the renamed file, its .gz archive
and the previous archive, which retention deletes only after the rotation.

- The test closes the writer before it lists the archives: close() stops
  the rotator and waits for a rotation in progress, so the listing sees
  the state that retention left.
- getAllHistoricalFiles() keeps only the last listing instead of adding
  each one to the previous ones, so a listing taken during a rotation no
  longer stays in the result; the unused existingFiles parameter is gone.

Fixes OpenIdentityPlatform#356
@vharseko vharseko added tests Test code changes java Pull requests that update java code concurrency Race conditions, locking and thread-safety labels Oct 17, 2026
@vharseko
vharseko requested a review from maximthomas October 17, 2026 13:27

@maximthomas maximthomas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: The fix goes where the race is: the test now lists the archives only after the rotator has stopped.

  • rotatableWriter.close() runs before assertRetainedHistoricalFiles (RotatableWriterTest.java:439-444). RotatableWriter.close() calls awaitTermination on the single scheduled task that rotates the file, compresses it (GzipUtil.compressRotatedFile) and applies retention, so the listing sees a directory nothing else is changing. I injected a 1500 ms sleep into compressRotatedFile and the test passed at this head (1/1, 4.4 s).
  • The reproduction table in the description shows what each half of the change does: the helper change alone still fails at 1500 ms, and the helper change plus close() passes.

@vharseko
vharseko merged commit c24cfc5 into OpenIdentityPlatform:master Oct 18, 2026
14 checks passed
@vharseko
vharseko deleted the issue-356-rotatable-writer-test-listing branch October 18, 2026 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

concurrency Race conditions, locking and thread-safety java Pull requests that update java code tests Test code changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky test: RotatableWriterTest.testAutomaticallyEvaluatesPolicesPeriodicallyIfRotationIntervalSpecified counts a rotation in progress

2 participants