Skip to content

Commit 4ac2bd6

Browse files
committed
fix tests, make them flake much, much less
On-behalf-of: @SAP [email protected]
1 parent 245ff8e commit 4ac2bd6

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ require (
3636
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
3737
github.com/cespare/xxhash/v2 v2.3.0 // indirect
3838
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
39+
github.com/egymgmbh/go-prefix-writer v0.0.0-20180609083313-7326ea162eca // indirect
3940
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
4041
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
4142
github.com/fatih/color v1.17.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
2121
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2222
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
2323
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
24+
github.com/egymgmbh/go-prefix-writer v0.0.0-20180609083313-7326ea162eca h1:7oodhZp9MZW0DBkrZXyUsJWKQFy35SVxjZ8K4vHXnk8=
25+
github.com/egymgmbh/go-prefix-writer v0.0.0-20180609083313-7326ea162eca/go.mod h1:UhMFM+dnOcm1f0Pve8uqRaxAhEYki+/CuA2BTDp2T04=
2426
github.com/emicklei/go-restful/v3 v3.12.1 h1:PJMDIM/ak7btuL8Ex0iYET9hxM3CI2sjZtzpL63nKAU=
2527
github.com/emicklei/go-restful/v3 v3.12.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
2628
github.com/evanphx/json-patch v5.9.0+incompatible h1:fBXyNpNMuTTDdquAq/uisOr2lShz4oaXpDTX2bLe7ls=

test/e2e/rootshards/proxy_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestRootShardProxy(t *testing.T) {
4747
ctx := context.Background()
4848

4949
namespace := utils.CreateSelfDestructingNamespace(t, ctx, client, "rootshard-proxy")
50-
externalHostname := fmt.Sprintf("front-proxy-front-proxy.e2e-%s.svc.cluster.local", namespace.Name)
50+
externalHostname := fmt.Sprintf("front-proxy-front-proxy.%s.svc.cluster.local", namespace.Name)
5151

5252
// deploy a root shard incl. etcd
5353
rootShard := utils.DeployRootShard(ctx, t, client, namespace.Name, externalHostname)

test/utils/utils.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030

3131
kcpcorev1alpha1 "github.com/kcp-dev/kcp/sdk/apis/core/v1alpha1"
3232
kcptenancyv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/tenancy/v1alpha1"
33+
"github.com/kcp-dev/kcp/sdk/testing/server"
3334
"github.com/kcp-dev/logicalcluster/v3"
3435

3536
corev1 "k8s.io/api/core/v1"
@@ -155,13 +156,18 @@ func SelfDestuctingPortForward(
155156
})
156157
}
157158

158-
var currentPort = 56029
159+
func getPort(t *testing.T) int {
160+
port, err := server.GetFreePort(t)
161+
if err != nil {
162+
t.Fatalf("Failed to get free port: %v", err)
163+
}
159164

160-
func getPort() int {
161-
port := currentPort
162-
currentPort++
165+
portNum, err := strconv.Atoi(port)
166+
if err != nil {
167+
t.Fatalf("Failed to parse port %q as number: %v", port, err)
168+
}
163169

164-
return port
170+
return portNum
165171
}
166172

167173
func ConnectWithKubeconfig(
@@ -214,7 +220,7 @@ func ConnectWithKubeconfig(
214220
}
215221

216222
// start a port forwarding
217-
localPort := getPort()
223+
localPort := getPort(t)
218224
SelfDestuctingPortForward(t, ctx, namespace, "svc/"+serviceName, int(portNum), localPort)
219225

220226
// patch the target server
@@ -256,7 +262,7 @@ func ConnectWithRootShardProxy(
256262
}
257263

258264
// start a port forwarding
259-
localPort := getPort()
265+
localPort := getPort(t)
260266
servicePort := 6443
261267
serviceName := resources.GetRootShardProxyServiceName(rootShard)
262268

0 commit comments

Comments
 (0)