Skip to content

Conversation

Kcruz28
Copy link

@Kcruz28 Kcruz28 commented Oct 3, 2025

This PR fixes a flaky test that was failing because of a race condition.

This pull request addresses intermittent test failures caused by relying on a fixed delay Thread.sleep() to wait for asynchronous operations. Fixed delays are unreliable because the operation may occasionally take longer than the predefined wait time.

This commit replaces the fixed delay with a polling mechanism using the Awaitility library. Awaitility continuously checks for the expected condition within a specified timeout, ensuring the test only proceeds once the desired state is reached. This makes the test more robust and reliable by synchronizing with actual operation completion rather than arbitrary timing.

Fixes: #3006

Important

Base your changes on 2.x branch if you are targeting Log4j 2; use main otherwise.

Checklist

Before we can review and merge your changes, please go through the checklist below. If you're still working on some items, feel free to submit your pull request as a draft—our CI will help guide you through the remaining steps.

✅ Required checks

  • License: I confirm that my changes are submitted under the Apache License, Version 2.0.

  • Commit signatures: All commits are signed and verifiable. (See GitHub Docs on Commit Signature Verification).

  • Code formatting: The code is formatted according to the project’s style guide.

    How to check and fix formatting
    • To check formatting: ./mvnw spotless:check
    • To fix formatting: ./mvnw spotless:apply

    See the build instructions for details.

  • Build & Test: I verified that the project builds and all unit tests pass.

    How to build the project

    Run: ./mvnw verify

    See the build instructions for details.

🧪 Tests (select one)

  • I have added or updated tests to cover my changes.
  • No additional tests are needed for this change.

📝 Changelog (select one)

  • I added a changelog entry in src/changelog/.2.x.x. (See Changelog Entry File Guide).
  • This is a trivial change and does not require a changelog entry.

The test  was failing intermittently due to a race condition in the test's base class, .

This commit replaces the fixed  with a more robust polling mechanism using the  library to ensure the test is stable and reliable.
@Kcruz28 Kcruz28 changed the title Fix(test): Address flakiness in SyslogAppenderCustomLayoutTest Fix: Replace fixed delay with Awaitility in SyslogAppenderCustomLayoutTest Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: To triage
Development

Successfully merging this pull request may close these issues.

SyslogAppenderCustomLayoutTest is unreliable
1 participant