Fix potential port conflict issue with the API server tests by using a random server port if --random-ports is set (#6995)

* Let the OS assign a random ephemeral port if `--random-ports` is specified when running `odo dev` or `odo api-server`

This should hopefully fix the potential port conflict flaky
issue we are seeing, especially on Windows.

* Do not allow setting `--random-ports` and a specific port value

This applies to:
- `odo dev --random-ports --api-server --api-server-port=<port>`
- `odo api-server --random-ports --port=<port>`
This commit is contained in:
Armel Soro
2023-07-21 09:52:24 +02:00
committed by GitHub
parent fadd1306ab
commit a4ee0e4cea
4 changed files with 58 additions and 13 deletions

View File

@@ -42,6 +42,23 @@ var _ = Describe("odo dev command with api server tests", func() {
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile.yaml"), filepath.Join(commonVar.Context, "devfile.yaml"), cmpName)
})
if customPort {
It("should fail if --random-ports and --api-server-port are used together", func() {
args := []string{
"dev",
"--random-ports",
"--api-server",
fmt.Sprintf("--api-server-port=%d", helper.GetCustomStartPort()),
}
if podman {
args = append(args, "--platform=podman")
}
errOut := helper.Cmd("odo", args...).AddEnv("ODO_EXPERIMENTAL_MODE=true").ShouldFail().Err()
Expect(errOut).Should(ContainSubstring("--random-ports and --api-server-port cannot be used together"))
})
}
When(fmt.Sprintf("odo dev is run with --api-server flag (custom api server port=%v)", customPort), func() {
var devSession helper.DevSession
var localPort int
@@ -53,6 +70,7 @@ var _ = Describe("odo dev command with api server tests", func() {
if customPort {
localPort = helper.GetCustomStartPort()
opts.APIServerPort = localPort
opts.NoRandomPorts = true
}
var err error
devSession, err = helper.StartDevMode(opts)