Skip to content

Commit

Permalink
Use order to iterate over ceMapping and fix a check with debug integr…
Browse files Browse the repository at this point in the history
…ation test

Signed-off-by: Parthvi Vala <[email protected]>
  • Loading branch information
valaparthvi committed Apr 17, 2023
1 parent 486c0a0 commit ecd00b1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 12 additions & 2 deletions pkg/dev/podmandev/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package podmandev
import (
"fmt"
"math/rand" // #nosec
"sort"
"time"

"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
Expand Down Expand Up @@ -56,7 +57,6 @@ func createPodFromComponent(
if err != nil {
return nil, nil, err
}
// }

utils.AddOdoProjectVolume(&containers)
utils.AddOdoMandatoryVolume(&containers)
Expand Down Expand Up @@ -229,7 +229,17 @@ func getPortMapping(devfileObj parser.DevfileObj, debug bool, randomPorts bool,
endPort := startPort + 10000
usedPortsCopy := make([]int, len(usedPorts))
copy(usedPortsCopy, usedPorts)
for containerName, endpoints := range ceMapping {

// Prepare to iterate over the ceMapping in an orderly fashion
// This ensures we iterate over the ceMapping in the same way every time, obtain the same result every time and avoid any flakes with tests
var containers []string
for container := range ceMapping {
containers = append(containers, container)
}
sort.Strings(containers)

for _, containerName := range containers {
endpoints := ceMapping[containerName]
epLoop:
for _, ep := range endpoints {
portName := ep.Name
Expand Down
7 changes: 2 additions & 5 deletions tests/integration/cmd_dev_debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,8 @@ var _ = Describe("odo dev debug command tests", func() {
// We are just using this to validate if nodejs agent is listening on the other side
url := fmt.Sprintf("http://%s", ports[ContainerDebugPort])
Expect(url).To(ContainSubstring(LocalDebugPort))
if !podman {
// this check doesn't work for podman unless we use --forward-localhost,
// but using it beats the purpose of testing with custom port mapping, so we skip this check
helper.HttpWaitForWithStatus(url, "WebSockets request was expected", 12, 5, 400)
}

helper.HttpWaitForWithStatus(url, "WebSockets request was expected", 12, 5, 400)
})
})
}))
Expand Down

0 comments on commit ecd00b1

Please sign in to comment.