Skip to content

Commit

Permalink
Add randomness to port selection allowing running concurrent e2e tests
Browse files Browse the repository at this point in the history
Useful for using stress to deflake test.

Signed-off-by: Marek Siarkowicz <[email protected]>
  • Loading branch information
serathius committed Aug 1, 2024
1 parent ca2d91c commit 8c93f8b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions tests/framework/e2e/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"errors"
"flag"
"fmt"
"math/rand"
"net/url"
"path"
"path/filepath"
Expand Down Expand Up @@ -399,7 +400,7 @@ func InitEtcdProcessCluster(t testing.TB, cfg *EtcdProcessClusterConfig) (*EtcdP
cfg.Logger = zaptest.NewLogger(t)
}
if cfg.BasePort == 0 {
cfg.BasePort = EtcdProcessBasePort
cfg.BasePort = EtcdProcessBasePort + rand.Int()%10000
}
if cfg.ServerConfig.SnapshotCount == 0 {
cfg.ServerConfig.SnapshotCount = etcdserver.DefaultSnapshotCount
Expand Down Expand Up @@ -502,12 +503,16 @@ func (cfg *EtcdProcessClusterConfig) SetInitialOrDiscovery(serverCfg *EtcdServer
func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfig(tb testing.TB, i int) *EtcdServerProcessConfig {
var curls []string
var curl string
port := cfg.BasePort + 5*i
port := cfg.BasePort + 6*i
clientPort := port
peerPort := port + 1
metricsPort := port + 2
peer2Port := port + 3
clientHTTPPort := port + 4
var gofailPort int
if cfg.GoFailEnabled {
gofailPort = port + 5
}

if cfg.Client.ConnectionType == ClientTLSAndNonTLS {
curl = clientURL(cfg.ClientScheme(), clientPort, ClientNonTLS)
Expand Down Expand Up @@ -628,9 +633,7 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfig(tb testing.TB, i in
for key, value := range cfg.EnvVars {
envVars[key] = value
}
var gofailPort int
if cfg.GoFailEnabled {
gofailPort = (i+1)*10000 + 2381
if gofailPort != 0 {
envVars["GOFAIL_HTTP"] = fmt.Sprintf("127.0.0.1:%d", gofailPort)
}

Expand Down

0 comments on commit 8c93f8b

Please sign in to comment.