Skip to content

Commit cb196ef

Browse files
berndverstAmit Mor
authored andcommitted
remove port allocation code in favor of dapr runtime testing package (dapr#1245)
Signed-off-by: Amit Mor <amitm@at-bay.com>
1 parent 3f0449b commit cb196ef

File tree

4 files changed

+9
-25
lines changed

4 files changed

+9
-25
lines changed

tests/certification/flow/network/network.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,3 @@ func InterruptNetwork(duration time.Duration, ipv4s []string, ipv6s []string, po
109109
return nil
110110
}
111111
}
112-
113-
// Helper function to return a random unused port number. Consecutive calls to this function will return different port numbers.
114-
func GetAvailablePort() (int, error) {
115-
addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
116-
if err != nil {
117-
return -1, err
118-
}
119-
120-
l, err := net.ListenTCP("tcp", addr)
121-
if err != nil {
122-
return -1, err
123-
}
124-
defer l.Close()
125-
126-
return l.Addr().(*net.TCPAddr).Port, nil
127-
}

tests/certification/secretstores/azure/keyvault/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ require (
8585
github.com/sirupsen/logrus v1.8.1 // indirect
8686
github.com/spf13/pflag v1.0.5 // indirect
8787
github.com/stoewer/go-strcase v1.2.0 // indirect
88-
github.com/tylertreat/comcast v1.0.1 // indirect
88+
github.com/stretchr/objx v0.2.0 // indirect
8989
github.com/valyala/bytebufferpool v1.0.0 // indirect
9090
github.com/valyala/fasthttp v1.28.0 // indirect
9191
go.opencensus.io v0.22.5 // indirect

tests/certification/secretstores/azure/keyvault/go.sum

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,6 @@ github.com/toolkits/concurrent v0.0.0-20150624120057-a4371d70e3e3/go.mod h1:QDlp
10561056
github.com/trusch/grpc-proxy v0.0.0-20190529073533-02b64529f274 h1:ChAMVBRng5Dsv0rnfOxUj7vg2M9D0rafbRY1N2EEAZ8=
10571057
github.com/trusch/grpc-proxy v0.0.0-20190529073533-02b64529f274/go.mod h1:dzrPb02OTNDVimdCCBR1WAPu9a69n3VnfDyCX/GT/gE=
10581058
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
1059-
github.com/tylertreat/comcast v1.0.1 h1:+B8add2s9PrhX4lx5gGqOKUTebGD7lzdfwKZHYoF98Y=
10601059
github.com/tylertreat/comcast v1.0.1/go.mod h1:8mA9mMCnmAGjTnrWNKQ7PXsBy6FfguO+U9pSxifaka8=
10611060
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
10621061
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=

tests/certification/secretstores/azure/keyvault/keyvault_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import (
1717
secretstore_env "github.com/dapr/components-contrib/secretstores/local/env"
1818
secretstores_loader "github.com/dapr/dapr/pkg/components/secretstores"
1919
"github.com/dapr/dapr/pkg/runtime"
20+
dapr_testing "github.com/dapr/dapr/pkg/testing"
2021
"github.com/dapr/kit/logger"
2122

2223
"github.com/dapr/components-contrib/tests/certification/embedded"
2324
"github.com/dapr/components-contrib/tests/certification/flow"
24-
"github.com/dapr/components-contrib/tests/certification/flow/network"
2525
"github.com/dapr/components-contrib/tests/certification/flow/sidecar"
2626
"github.com/dapr/go-sdk/client"
2727
)
@@ -31,11 +31,12 @@ const (
3131
)
3232

3333
func TestKeyVault(t *testing.T) {
34-
currentGrpcPort, err := network.GetAvailablePort()
35-
assert.NoError(t, err)
36-
currentHttpPort, err := network.GetAvailablePort()
34+
ports, err := dapr_testing.GetFreePorts(2)
3735
assert.NoError(t, err)
3836

37+
currentGrpcPort := ports[0]
38+
currentHttpPort := ports[1]
39+
3940
log := logger.NewLogger("dapr.components")
4041

4142
testGetKnownSecret := func(ctx flow.Context) error {
@@ -76,10 +77,10 @@ func TestKeyVault(t *testing.T) {
7677
Run()
7778

7879
// Currently port reuse is still not quite working in the Dapr runtime.
79-
currentGrpcPort, err = network.GetAvailablePort()
80-
assert.NoError(t, err)
81-
currentHttpPort, err = network.GetAvailablePort()
80+
ports, err = dapr_testing.GetFreePorts(2)
8281
assert.NoError(t, err)
82+
currentGrpcPort = ports[0]
83+
currentHttpPort = ports[1]
8384

8485
flow.New(t, "keyvault authentication using certificate").
8586
Step(sidecar.Run(sidecarName,

0 commit comments

Comments
 (0)