Skip to content

test: deduplicate GetFreePort helpers#17

Open
chethanuk wants to merge 2 commits into
mainfrom
fix/issue-1188-getfreeport-dedup
Open

test: deduplicate GetFreePort helpers#17
chethanuk wants to merge 2 commits into
mainfrom
fix/issue-1188-getfreeport-dedup

Conversation

@chethanuk

@chethanuk chethanuk commented Jul 19, 2026

Copy link
Copy Markdown
Owner

User description

What type of PR is this?

/kind cleanup
/kind test

What this PR does / why we need it:

Two copies of a "give me a free TCP port" test helper existed with divergent
signatures:

  • test/integration/util.goGetFreePort() (int, error), IPv4 127.0.0.1:0
  • test/utils/network.goGetFreePort() (string, error), dual-stack :0

This PR collapses them into a single canonical GetFreePort() (int, error)
living in the lightweight test/utils package. The direction is forced by
imports: pkg/sidecar/proxy (via test/utils) must not pull in the heavy
test/integration EPP/k8s dependency tree, so the shared helper belongs in
test/utils.

Changes:

  • test/utils/network.go: canonical GetFreePort() (int, error), IPv4
    127.0.0.1:0 (keeps the anti-dual-stack-flake behavior).
  • test/integration/util.go: delete the duplicate helper; drop the now-unused
    errors import.
  • test/integration/epp/harness.go: migrate the 3 call sites in
    defaultEppServerOptions to testutils.GetFreePort().
  • pkg/sidecar/proxy/data_parallel_test.go: the int return drops a
    strconv.Atoi round-trip.
  • test/utils/network_test.go: table-driven test that the helper returns an
    in-range, actually-bindable port.

Pure test-infra refactor, no product code. Net negative diff.

Which issue(s) this PR fixes:

Fixes llm-d#1188

Release note:

NONE

CodeAnt-AI Description

Use one shared helper for finding a free test port

What Changed

  • Test code now uses a single shared helper to find an available IPv4 localhost port, instead of two different versions with different return values.
  • Integration tests that start the EPP service now get ports from the shared helper.
  • The sidecar data-parallel test now uses the port number directly, avoiding a text-to-number conversion step.
  • The free-port helper now has a test that checks it returns a valid, bindable port.

Impact

✅ Fewer flaky test port conflicts
✅ Consistent test setup across suites
✅ Shorter test startup path

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

Summary by CodeRabbit

  • Bug Fixes

    • Improved test networking reliability by allocating valid, available IPv4 localhost ports consistently.
    • Prevented port conflicts during concurrent or repeated test runs.
  • Tests

    • Added coverage verifying returned ports are valid, unique while in use, bindable, and properly released.
    • Updated integration and proxy test setups to use the standardized port allocation behavior.

Two copies of a free-port helper existed with divergent signatures:
test/integration/util.go returned (int, error) on IPv4 127.0.0.1:0, and
test/utils/network.go returned (string, error) on dual-stack :0.

Consolidate to a single canonical GetFreePort (int, error) in the
lightweight test/utils package (the sidecar test tree cannot import the
heavy test/integration tree). Delete the integration copy, migrate the
three harness call sites, and drop the now-redundant strconv.Atoi in the
sidecar data-parallel test.

Refs: llm-d#1188
Signed-off-by: ChethanUK <chethanuk@outlook.com>
@codeant-ai

codeant-ai Bot commented Jul 19, 2026

Copy link
Copy Markdown

🤖 CodeAnt AI — Review Status

Status Commit Started (UTC) Finished (UTC)
✅ Reviewed your PR abab37e Jul 19, 2026 · 11:38 11:41

Updated in place by CodeAnt AI · last 5 reviews

@codeant-ai

codeant-ai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3c87027d-186c-4a08-af57-987fdb690c92

📥 Commits

Reviewing files that changed from the base of the PR and between c82561b and 1560ec6.

📒 Files selected for processing (5)
  • pkg/sidecar/proxy/data_parallel_test.go
  • test/integration/epp/harness.go
  • test/integration/util.go
  • test/utils/network.go
  • test/utils/network_test.go
💤 Files with no reviewable changes (1)
  • test/integration/util.go

📝 Walkthrough

Walkthrough

The shared test port helper now returns an integer bound to IPv4 localhost. Integration EPP setup uses it for server ports, the old integration helper is removed, and the data-parallel test adjusts to integer port handling.

Changes

Test port allocation

Layer / File(s) Summary
Integer port helper and validation
test/utils/network.go, test/utils/network_test.go
GetFreePort returns an IPv4 localhost port as an integer with updated errors, and tests validate range, uniqueness, and bindability.
Integration harness migration
test/integration/epp/harness.go, test/integration/util.go
EPP server ports use testutils.GetFreePort, and the former integration-local helper is removed.
Sidecar test port handling
pkg/sidecar/proxy/data_parallel_test.go
Fake proxy ports are computed directly from integers, with local declaration of the parsed rank-1 port.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: elevran, roytman

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: consolidating duplicate GetFreePort helpers in test code.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-1188-getfreeport-dedup

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codeant-ai codeant-ai Bot added the size:M This PR changes 30-99 lines, ignoring generated files label Jul 19, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request consolidates the GetFreePort utility function into test/utils/network.go, refactoring it to return an integer port instead of a string and forcing IPv4 localhost. This change is propagated across tests in pkg/sidecar/proxy/data_parallel_test.go and test/integration/epp/harness.go, and the duplicate implementation in test/integration/util.go is removed. A new test file test/utils/network_test.go is also added. The reviewer pointed out that the test case "returns a distinct bindable port on repeat call" does not actually verify distinct ports because it uses the same logic as the first test case in the table-driven loop, and suggested rewriting the test to explicitly call GetFreePort twice while keeping the first port bound.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

The table-driven TestGetFreePort had two named cases sharing one body, so
the second case never verified that repeat calls return distinct ports.
Allocate N ports while holding each listener open, which forces the OS to
hand out a fresh port per call, and assert range, bindability, and
distinctness together.

Signed-off-by: ChethanUK <chethanuk@outlook.com>
Repository owner deleted a comment from gemini-code-assist Bot Jul 19, 2026
Repository owner deleted a comment from codeant-ai Bot Jul 19, 2026
Repository owner deleted a comment from codeant-ai Bot Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L size:M This PR changes 30-99 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Testing] Consolidate Hermetic Integration Test Helpers into Structured test/framework

1 participant