Skip to content

Commit

Permalink
Make sure all ports are allocated at once to minimize clashes
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio committed Feb 6, 2025
1 parent dda2a98 commit b78154c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,11 @@ func (i *Test) spawnRPCDaemon() {
// We need to dynamically allocate port numbers since tests run in parallel.
// Unfortunately this isn't completely clash-free,
// but there is no way to tell core to allocate the port dynamically
i.testPorts.captiveCorePort = getFreeTCPPort(i.t)
freePorts := getFreeTCPPorts(i.t, 3)
i.testPorts.captiveCorePort = freePorts[0]
if i.enableCoreHTTPQueryServer {
i.testPorts.captiveCoreHTTPQueryPort = getFreeTCPPort(i.t)
i.testPorts.captiveCoreHTTPPort = getFreeTCPPort(i.t)
i.testPorts.captiveCoreHTTPQueryPort = freePorts[1]
i.testPorts.captiveCoreHTTPPort = freePorts[2]
}
i.generateCaptiveCoreCfgForDaemon()
rpcCfg := i.getRPConfigForDaemon()
Expand Down
22 changes: 13 additions & 9 deletions cmd/stellar-rpc/internal/integrationtest/infrastructure/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ func GetCurrentDirectory() string {
return filepath.Dir(currentFilename)
}

func getFreeTCPPort(t require.TestingT) uint16 {
var a *net.TCPAddr
a, err := net.ResolveTCPAddr("tcp", "localhost:0")
require.NoError(t, err)
var l *net.TCPListener
l, err = net.ListenTCP("tcp", a)
require.NoError(t, err)
defer l.Close()
return uint16(l.Addr().(*net.TCPAddr).Port)
func getFreeTCPPorts(t require.TestingT, count int) []uint16 {
result := make([]uint16, count)
for i := range count {
var a *net.TCPAddr
a, err := net.ResolveTCPAddr("tcp", "localhost:0")
require.NoError(t, err)
var l *net.TCPListener
l, err = net.ListenTCP("tcp", a)
require.NoError(t, err)
defer l.Close()
result[i] = uint16(l.Addr().(*net.TCPAddr).Port)

Check failure on line 29 in cmd/stellar-rpc/internal/integrationtest/infrastructure/util.go

View workflow job for this annotation

GitHub Actions / golangci-lint

type assertion must be checked (forcetypeassert)
}
return result
}

func CreateTransactionParams(account txnbuild.Account, op txnbuild.Operation) txnbuild.TransactionParams {
Expand Down

0 comments on commit b78154c

Please sign in to comment.