Skip to content

[java] Chore/test fluent wait avoiding thread sleep - #17983

Open
iampopovich wants to merge 2 commits into
SeleniumHQ:trunkfrom
iampopovich:chore/test-fluent-wait-avoiding-thred-sleep
Open

[java] Chore/test fluent wait avoiding thread sleep#17983
iampopovich wants to merge 2 commits into
SeleniumHQ:trunkfrom
iampopovich:chore/test-fluent-wait-avoiding-thred-sleep

Conversation

@iampopovich

@iampopovich iampopovich commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

🔗 Related Issues

There is no associated issue for these changes. The changes are proposed to potentially reduce test run times.

💥 What does this PR do?

This pull request improves the reliability and determinism of concurrency tests in LocalSessionMapTest by replacing arbitrary Thread.sleep calls with CountDownLatch synchronization. It also makes minor code cleanups in MBean.java for string emptiness checks.

Test synchronization and reliability improvements:

  • Replaced all Thread.sleep calls in LocalSessionMapTest with CountDownLatch and a new awaitPrerequisite helper method, ensuring that test steps wait precisely for required operations to complete rather than relying on timing. This makes the tests less flaky and more robust under high concurrency.

Code quality improvements:

  • Updated string emptiness checks in MBean.java to use isEmpty() instead of comparing with "", improving readability and consistency.

🔧 Implementation Notes

🤖 AI assistance

  • No substantial AI assistance used
  • AI assisted (complete below)
    • Tool(s): claude code + Sonnet 5 medium effort + copilot for diff summary
    • What was generated: A plan for finding time leaks in waits when running tests. A helper for synchronizing waits.
    • I reviewed all AI output and can explain the change

💡 Additional Considerations

🔄 Types of changes

  • Cleanup (formatting, renaming)

@iampopovich iampopovich self-assigned this Sep 5, 2026
@selenium-ci selenium-ci added B-grid Everything grid and server related C-java Java Bindings labels Sep 5, 2026
@iampopovich
iampopovich marked this pull request as ready for review September 5, 2026 03:58
Copilot AI lite review requested due to automatic review settings September 5, 2026 03:58
@qodo-code-review

Copy link
Copy Markdown
Contributor

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

Copilot AI 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.

🟡 Changes recommended

The new awaitPrerequisite assertion can be silently swallowed inside executor.submit(...) tasks (since Futures aren’t checked), so prerequisite timeouts may not actually fail the tests.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR updates the Java Grid LocalSessionMapTest concurrency tests to avoid using Thread.sleep for ordering, replacing it with CountDownLatch-based synchronization to make the tests more deterministic under concurrency. It also includes a small cleanup in MBean to use String#isEmpty() for annotation attribute checks.

Changes:

  • Replaced timing-based sleeps in LocalSessionMapTest concurrency scenarios with CountDownLatch sequencing and a shared awaitPrerequisite helper.
  • Updated MBean annotation attribute empty-string checks to use isEmpty() instead of equals("").
File summaries
File Description
java/test/org/openqa/selenium/grid/sessionmap/local/LocalSessionMapTest.java Replaces Thread.sleep with latch-based ordering and adds awaitPrerequisite helper for concurrent test determinism.
java/src/org/openqa/selenium/grid/jmx/MBean.java Uses String#isEmpty() for clearer empty checks on annotation attributes.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +715 to +719
private static void awaitPrerequisite(CountDownLatch latch) throws InterruptedException {
assertThat(latch.await(30, TimeUnit.SECONDS))
.as("Timed out waiting for a prerequisite operation to complete")
.isTrue();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

B-grid Everything grid and server related C-java Java Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants