Skip to content

Commit

Permalink
Merge pull request #1415 from orbs-network/fix/retry-e2e-port-allocation
Browse files Browse the repository at this point in the history
retry allocating a free port for e2e gossip until getting a free port
  • Loading branch information
electricmonk authored Nov 1, 2019
2 parents e3c406d + b617676 commit f027b5d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion test/e2e/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/orbs-network/orbs-network-go/test/rand"
"github.com/orbs-network/orbs-spec/types/go/primitives"
"github.com/orbs-network/scribe/log"
"net"
"os"
)

Expand Down Expand Up @@ -54,5 +55,15 @@ func (t *loggerRandomer) Name() string {
}

func (t *loggerRandomer) aRandomPort() int {
return firstEphemeralPort + t.rnd.Intn(maxPort-LOCAL_NETWORK_SIZE*2-firstEphemeralPort)
for {
port := firstEphemeralPort + t.rnd.Intn(maxPort-LOCAL_NETWORK_SIZE*2-firstEphemeralPort)
l, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", port))
if err == nil {
_ = l.Close()
t.logger.Info("port is free, returning", log.Int("port", port))
return port
} else {
t.logger.Info("port is already in use, retrying a different port", log.Int("port", port))
}
}
}

0 comments on commit f027b5d

Please sign in to comment.