Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request vitessio#5934 from planetscale/ds-debug-cluster-tests
Browse files Browse the repository at this point in the history
tests: check whether port is available before reserving
  • Loading branch information
deepthi committed Mar 17, 2020
2 parents 5c31833 + 2b38b56 commit 9e74b07
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion go/test/endtoend/cluster/cluster_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"io/ioutil"
"math/rand"
"net"
"os"
"os/exec"
"os/signal"
Expand Down Expand Up @@ -576,7 +577,20 @@ func (cluster *LocalProcessCluster) GetAndReservePort() int {
if cluster.nextPortForProcess == 0 {
cluster.nextPortForProcess = getPort()
}
cluster.nextPortForProcess = cluster.nextPortForProcess + 1
for {
cluster.nextPortForProcess = cluster.nextPortForProcess + 1
log.Errorf("Attempting to reserve port: %v", cluster.nextPortForProcess)
ln, err := net.Listen("tcp", fmt.Sprintf(":%v", cluster.nextPortForProcess))

if err != nil {
log.Errorf("Can't listen on port %v: %s, trying next port", cluster.nextPortForProcess, err)
continue
}

ln.Close()
log.Errorf("Port %v is available, reserving..", cluster.nextPortForProcess)
break
}
return cluster.nextPortForProcess
}

Expand Down

0 comments on commit 9e74b07

Please sign in to comment.