Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions integration-tests/suites/listening_ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package suites
import (
"fmt"
"io"
"net"
"net/http"
"sort"
"time"
Expand Down Expand Up @@ -57,10 +58,12 @@ func (s *ProcessListeningOnPortTestSuite) SetupSuite() {
ports, err := s.getPorts(serverName)
s.Require().NoError(err)

s.serverURL = fmt.Sprintf("http://%s:%d", ip, ports[0])
serverAddr := net.JoinHostPort(ip, fmt.Sprint(ports[0]))
s.serverURL = "http://" + serverAddr

// Wait 5 seconds for the plop service to start
common.Sleep(5 * time.Second)
// Flask usually binds within a few seconds, but a cold start on some
// VMs (e.g. ubuntu-2404) has been seen to take longer than that.
s.waitForServer(serverAddr, 15*time.Second)

log.Info("Opening ports...")
s.openPort(8081)
Expand Down Expand Up @@ -146,6 +149,20 @@ func getProcessListeningOnPortsImage() string {
return config.Images().QaImageByKey("qa-plop")
}

// waitForServer polls until the plop server accepts TCP connections on addr,
// failing the suite if it doesn't within timeout.
func (s *ProcessListeningOnPortTestSuite) waitForServer(addr string, timeout time.Duration) {
log.Info("Waiting for plop server on %s...", addr)
s.Require().Eventually(func() bool {
conn, err := net.DialTimeout("tcp", addr, time.Second)
if err != nil {
return false
}
conn.Close()
return true
}, timeout, 500*time.Millisecond, "plop server did not start listening on %s within %s", addr, timeout)
}

func (s *ProcessListeningOnPortTestSuite) openPort(port uint16) {
res, err := http.Get(fmt.Sprintf("%s/open/%d", s.serverURL, port))
s.Require().NoError(err)
Expand Down
Loading