Skip to content

test(opensearch): pin OpenSearchRunner HTTP port to avoid flaky tests#171

Merged
marevol merged 1 commit into
masterfrom
test/fix-flaky-opensearch-port
Jun 18, 2026
Merged

test(opensearch): pin OpenSearchRunner HTTP port to avoid flaky tests#171
marevol merged 1 commit into
masterfrom
test/fix-flaky-opensearch-port

Conversation

@marevol

@marevol marevol commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Summary

The OpenSearch backend tests intermittently fail to start the embedded node with "Address already in use". OpenSearchRunner selects its HTTP port via a connect-based scan that can report a port as free even when it is already bound on the IPv6 loopback ([::1]), so the node occasionally tries to bind a port that is not actually available. This PR makes the test setup deterministic by reserving a free ephemeral port up front and pinning the runner to it.

Changes Made

  • Added OpenSearchRunnerUtil test helper with findFreePort(), which asks the OS for an ephemeral port via new ServerSocket(0).
  • Updated CrawlerTest, OpenSearchDataServiceTest, OpenSearchUrlFilterServiceTest, and OpenSearchUrlQueueServiceTest to:
    • Reserve a free port before building the runner.
    • Disable the unreliable port scan via runner.setMaxHttpPort(-1).
    • Pass baseHttpPort(httpPort - 1) so the first node binds to the reserved port (the runner uses baseHttpPort + 1 for the first node).
    • Use the reserved port as the fallback value for the FesenClient.HTTP_ADDRESS system property.

Testing

  • Test-only change. Run the OpenSearch module tests (mvn test -pl fess-crawler-opensearch) to confirm the embedded node starts reliably.

Breaking Changes

  • None. Changes are limited to test code.

Additional Notes

  • The same setup pattern is duplicated across the four test classes for consistency; the shared logic lives in OpenSearchRunnerUtil.

OpenSearchRunner selects an HTTP port via an unreliable connect-based scan
that can report a port as free even when it is bound on IPv6, causing
intermittent "Address already in use" failures. Reserve a free ephemeral
port up front, disable the scan, and pin the runner to it.

Claude-Session: https://claude.ai/code/session_0177Ci4EJFMP7jyQQ5XdBgu3
@marevol marevol merged commit f33fad2 into master Jun 18, 2026
1 check passed
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.

1 participant