Skip to content

[Backport] [1.x] Use try-with-resources with MockLogAppender (#1595)#1784

Merged
adnapibar merged 1 commit into
opensearch-project:1.xfrom
andrross:backport-mock-appender-twr
Dec 22, 2021
Merged

[Backport] [1.x] Use try-with-resources with MockLogAppender (#1595)#1784
adnapibar merged 1 commit into
opensearch-project:1.xfrom
andrross:backport-mock-appender-twr

Conversation

@andrross
Copy link
Copy Markdown
Member

I previously added a helper that started a MockLogAppender to ensure it
was never added to a Logger before it was started. I subsequently found
the opposite case in RolloverIT.java where the appender was stopped
before it was closed, therefore creating a race where a concurrently
running test in the same JVM could cause a logging failure. This seems
like a really easy mistake to make when writing a test or introduce when
refactoring a test. I've made a change to use try-with-resources to
ensure that proper setup and teardown is done. This should make it much
harder to introduce this particular test bug in the future.
Unfortunately, it did involve touching a lot of files. The changes here
are purely structural to leverage try-with-resources; no testing logic
has been changed.

Signed-off-by: Andrew Ross andrross@amazon.com

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

I previously added a helper that started a MockLogAppender to ensure it
was never added to a Logger before it was started. I subsequently found
the opposite case in RolloverIT.java where the appender was stopped
before it was closed, therefore creating a race where a concurrently
running test in the same JVM could cause a logging failure. This seems
like a really easy mistake to make when writing a test or introduce when
refactoring a test. I've made a change to use try-with-resources to
ensure that proper setup and teardown is done. This should make it much
harder to introduce this particular test bug in the future.
Unfortunately, it did involve touching a lot of files. The changes here
are purely structural to leverage try-with-resources; no testing logic
has been changed.

Signed-off-by: Andrew Ross <andrross@amazon.com>
@opensearch-ci-bot
Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@opensearch-ci-bot
Copy link
Copy Markdown
Collaborator

❌   Gradle Check failure 50b48dc
Log 1611

Reports 1611

@andrross
Copy link
Copy Markdown
Member Author

start gradle check

@opensearch-ci-bot
Copy link
Copy Markdown
Collaborator

✅   Gradle Check success 50b48dc
Log 1614

Reports 1614

@adnapibar adnapibar merged commit 8cb54cd into opensearch-project:1.x Dec 22, 2021
@andrross andrross deleted the backport-mock-appender-twr branch December 22, 2021 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants