Skip to content

test: move GetFreePort into test/framework/net#30

Open
chethanuk wants to merge 1 commit into
feat/1188-framework-wiringfrom
feat/1188-net-move
Open

test: move GetFreePort into test/framework/net#30
chethanuk wants to merge 1 commit into
feat/1188-framework-wiringfrom
feat/1188-net-move

Conversation

@chethanuk

Copy link
Copy Markdown
Owner

What type of PR is this?

/kind cleanup
/kind test

What this PR does / why we need it:

Second of eight in the llm-d#1188 split. It follows the Makefile wiring PR that creates
test/framework and puts it under make test-unit.

GetFreePort is a network helper. It sat in test/utils, which is how a package
becomes a grab bag: nothing in the name says what belongs there, so everything does.
test/framework/net is where a port helper belongs.

The move is verbatim. The function body is unchanged; the deltas are the package
clause, the llm-d license header and a package comment, none of which
test/utils/network.go carried. Callers switch to the fwknet alias that
.golangci.yml already declares.

test/framework/net imports nothing from pkg/, so it stays an R1 leaf under the
layering rules in test/framework/doc.go. The chain moves one leaf package per PR so
each is revertable on its own, with the harness last because it is the heaviest.

Test plan:

  • go build and go vet ./test/... clean at this commit
  • go test ./test/framework/... passes, including the moved test

Which issue(s) this PR fixes:

Part of llm-d#1188

Release note (write NONE if no user-facing change):

NONE

GetFreePort is a network helper, not a general test util. Moving it into the
test/framework tree gives it an obvious home and keeps test/utils from growing
into a grab bag. The function body is unchanged; the only edit is the package
clause plus a license header and package comment on the new file.

Part of llm-d#1188

Signed-off-by: ChethanUK <chethanuk@outlook.com>
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ee7791bb-61ab-4486-a9ff-6749da38d54d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/1188-net-move

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.

@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 refactors the test network utilities by renaming the package from utils to net under test/framework/net and updating its usages across the codebase. Feedback points out that calling GetFreePort() sequentially to allocate ports for multiple services can lead to port collision flakes in tests, and suggests introducing a helper function to allocate multiple distinct ports simultaneously.

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.

Comment on lines +303 to 313
metricsPort, err := fwknet.GetFreePort()
require.NoError(t, err)
eppOptions.MetricsPort = metricsPort

grpcPort, err := testutils.GetFreePort()
grpcPort, err := fwknet.GetFreePort()
require.NoError(t, err)
eppOptions.GRPCPort = grpcPort

healthPort, err := testutils.GetFreePort()
healthPort, err := fwknet.GetFreePort()
require.NoError(t, err)
eppOptions.GRPCHealthPort = healthPort

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Calling GetFreePort() multiple times sequentially to allocate ports for different services (MetricsPort, GRPCPort, GRPCHealthPort) can lead to port collision flakes. Since GetFreePort() immediately closes the listener, the OS may return the same ephemeral port for subsequent calls if they occur in rapid succession before any server binds to them. Consider adding a helper like GetFreePorts(n int) ([]int, error) in the fwknet package that keeps all listeners open until all requested ports are allocated, ensuring they are distinct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant