Skip to content

Fix OptPorts to wait for listening ports, not exposed port#40

Merged
djthorpe merged 2 commits intomainfrom
djt/0328/portfix
Mar 28, 2026
Merged

Fix OptPorts to wait for listening ports, not exposed port#40
djthorpe merged 2 commits intomainfrom
djt/0328/portfix

Conversation

@djthorpe
Copy link
Copy Markdown
Member

This pull request updates how container ports are exposed and waited for in tests. Instead of waiting for just one port, the system now waits for each requested port individually. The related test has been updated to check for multiple ports and their corresponding wait strategies.

Port exposure and waiting improvements:

  • Modified OptPorts in opt.go to wait for each requested port individually by appending a wait.ForListeningPort strategy for every port, instead of a single generic wait.
  • Updated the Test_Opt_001 test in opt_test.go to use multiple ports ("3389/tcp", "389/tcp"), verify that both are exposed, and check that a wait strategy is set up for each port. [1] [2]

Copilot AI review requested due to automatic review settings March 28, 2026 09:08
@djthorpe djthorpe self-assigned this Mar 28, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts container test configuration so OptPorts waits for each explicitly requested port to be listening (instead of using a generic “exposed port” wait), and updates the related unit test accordingly.

Changes:

  • Update OptPorts to append wait.ForListeningPort for every requested port.
  • Update Test_Opt_001 to cover multiple ports and the corresponding per-port wait strategies.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/test/opt.go Changes port option behavior to add a listening-port wait strategy for each requested port.
pkg/test/opt_test.go Updates the option unit test to assert multiple exposed ports and multiple wait strategies.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +55 to 62
// OptPorts exposes one or more container ports and waits for each requested port.
func OptPorts(ports ...string) Opt {
return func(o *opts) error {
o.req.ExposedPorts = ports
o.appendWaitStrategy(wait.ForExposedPort())
for _, port := range ports {
o.appendWaitStrategy(wait.ForListeningPort(nat.Port(port)))
}
return nil
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

OptPorts now appends no wait strategy when called with zero ports. Given NewContainer falls back to wait.ForExit() when no strategies are present, an accidental OptPorts() call can cause long-running containers to hang. Consider returning an error when len(ports)==0 (or explicitly documenting/handling the empty case).

Copilot uses AI. Check for mistakes.
@djthorpe djthorpe merged commit 7e50302 into main Mar 28, 2026
1 check passed
@djthorpe djthorpe deleted the djt/0328/portfix branch March 28, 2026 09:14
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.

2 participants