Skip to content

Commit 902e88f

Browse files
EtiennePerotgvisor-bot
authored andcommitted
Docker tests and benchmarks: Remove use of exposed ports.
All these tests and benchmarks rely on networking between containers, not on these ports being exposed on the host, so there is no need to expose them on the host. This avoids random errors like "Error starting userland proxy: listen tcp4 0.0.0.0:12345: bind: address already in use". #codehealth PiperOrigin-RevId: 778272096
1 parent a437d8d commit 902e88f

File tree

7 files changed

+11
-35
lines changed

7 files changed

+11
-35
lines changed

pkg/test/dockerutil/container.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ type RunOpts struct {
7777
// Cpus in which to allow execution. ("0", "1", "0-2").
7878
CpusetCpus string
7979

80-
// Ports are the ports to be allocated.
81-
Ports []int
82-
8380
// WorkDir sets the working directory.
8481
WorkDir string
8582

@@ -303,11 +300,6 @@ func (c *Container) create(ctx context.Context, profileImage string, conf *conta
303300
}
304301

305302
func (c *Container) config(ctx context.Context, r RunOpts, args []string) (*container.Config, error) {
306-
ports := nat.PortSet{}
307-
for _, p := range r.Ports {
308-
port := nat.Port(fmt.Sprintf("%d", p))
309-
ports[port] = struct{}{}
310-
}
311303
env := append(r.Env, fmt.Sprintf("RUNSC_TEST_NAME=%s", c.Name))
312304

313305
image := testutil.ImageByName(r.Image)
@@ -338,13 +330,12 @@ func (c *Container) config(ctx context.Context, r RunOpts, args []string) (*cont
338330
}
339331

340332
return &container.Config{
341-
Image: image,
342-
Cmd: args,
343-
Entrypoint: entrypoint,
344-
ExposedPorts: ports,
345-
Env: env,
346-
WorkingDir: r.WorkDir,
347-
User: r.User,
333+
Image: image,
334+
Cmd: args,
335+
Entrypoint: entrypoint,
336+
Env: env,
337+
WorkingDir: r.WorkDir,
338+
User: r.User,
348339
}, nil
349340
}
350341

test/benchmarks/database/redis_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,7 @@ func doBenchmarkRedis(b *testing.B, ops []string) {
8080
defer server.CleanUp(ctx)
8181

8282
// The redis docker container takes no arguments to run a redis server.
83-
if err := server.Spawn(ctx, dockerutil.RunOpts{
84-
Image: "benchmarks/redis",
85-
Ports: []int{port},
86-
}); err != nil {
83+
if err := server.Spawn(ctx, dockerutil.RunOpts{Image: "benchmarks/redis"}); err != nil {
8784
b.Fatalf("failed to start redis server with: %v", err)
8885
}
8986
defer metricsviz.FromContainerLogs(ctx, b, server)

test/benchmarks/network/httpd_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,9 @@ func benchmarkHttpdContinuous(b *testing.B, concurrency []int, sizes []string) {
112112
// runHttpd configures the static serving methods to run httpd.
113113
func runHttpd(b *testing.B, hey *tools.Hey) {
114114
// httpd runs on port 80.
115-
port := 80
115+
const port = 80
116116
httpdRunOpts := dockerutil.RunOpts{
117117
Image: "benchmarks/httpd",
118-
Ports: []int{port},
119118
Env: []string{
120119
// Standard environmental variables for httpd.
121120
"APACHE_RUN_DIR=/tmp",

test/benchmarks/network/iperf_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,7 @@ func BenchmarkIperfOneConnection(b *testing.B) {
7979
port := 5001
8080

8181
// Start the server.
82-
if err := server.Spawn(ctx, dockerutil.RunOpts{
83-
Image: "benchmarks/iperf",
84-
Ports: []int{port},
85-
}, "iperf", "-s"); err != nil {
82+
if err := server.Spawn(ctx, dockerutil.RunOpts{Image: "benchmarks/iperf"}, "iperf", "-s"); err != nil {
8683
b.Fatalf("failed to start server with: %v", err)
8784
}
8885
if out, err := server.WaitForOutput(ctx, fmt.Sprintf("Server listening on TCP port %d", port), 10*time.Second); err != nil {
@@ -192,10 +189,7 @@ func BenchmarkIperfManyConnections(b *testing.B) {
192189
port := 5001
193190

194191
// Start the server.
195-
if err := server.Spawn(ctx, dockerutil.RunOpts{
196-
Image: "benchmarks/iperf",
197-
Ports: []int{port},
198-
}, "iperf", "-s"); err != nil {
192+
if err := server.Spawn(ctx, dockerutil.RunOpts{Image: "benchmarks/iperf"}, "iperf", "-s"); err != nil {
199193
b.Fatalf("failed to start server with: %v", err)
200194
}
201195
if out, err := server.WaitForOutput(ctx, fmt.Sprintf("Server listening on TCP port %d", port), 10*time.Second); err != nil {

test/benchmarks/network/nginx_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,7 @@ func benchmarkNginxContinuous(b *testing.B, concurrency []int, sizes []string) {
127127
func runNginx(b *testing.B, hey *tools.Hey, tmpfs bool) {
128128
// nginx runs on port 80.
129129
port := 80
130-
nginxRunOpts := dockerutil.RunOpts{
131-
Image: "benchmarks/nginx",
132-
Ports: []int{port},
133-
}
130+
nginxRunOpts := dockerutil.RunOpts{Image: "benchmarks/nginx"}
134131

135132
nginxCmd := []string{"nginx", "-c", "/etc/nginx/nginx_gofer.conf"}
136133
if tmpfs {

test/benchmarks/network/node_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ func runNode(b *testing.B, hey *tools.Hey) {
9898
Image: "benchmarks/node",
9999
WorkDir: "/usr/src/app",
100100
Links: []string{redis.MakeLink("redis")},
101-
Ports: []int{port},
102101
}, "node", "index.js", redisIP.String()); err != nil {
103102
b.Fatalf("failed to spawn node instance: %v", err)
104103
}

test/benchmarks/network/ruby_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ func runRuby(b *testing.B, hey *tools.Hey) {
9292
Image: "benchmarks/ruby",
9393
WorkDir: "/app",
9494
Links: []string{redis.MakeLink("redis")},
95-
Ports: []int{port},
9695
Env: []string{
9796
fmt.Sprintf("PORT=%d", port),
9897
"WEB_CONCURRENCY=20",

0 commit comments

Comments
 (0)