Skip to content

Commit bad432f

Browse files
authored
test: shift test ports to avoid linux ephemeral port range (GoogleCloudPlatform#2588)
This change moves the hardcoded ports in proxy_test.go from the 50000-60000 range to the 24000-26000 range. The linux ephemeral port range typically starts at port 32768 (or 36000), which was causing intermittent 'address already in use' failures in the tests.
1 parent 24a5ab1 commit bad432f

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

internal/proxy/proxy_test.go

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -132,63 +132,63 @@ func TestClientInitialization(t *testing.T) {
132132
desc: "multiple instances",
133133
in: &proxy.Config{
134134
Addr: "127.0.0.1",
135-
Port: 51000,
135+
Port: 25000,
136136
Instances: []proxy.InstanceConnConfig{
137137
{Name: pg},
138138
{Name: mysql},
139139
{Name: sqlserver},
140140
},
141141
},
142-
wantTCPAddrs: []string{"127.0.0.1:51000", "127.0.0.1:51001", "127.0.0.1:51002"},
142+
wantTCPAddrs: []string{"127.0.0.1:25000", "127.0.0.1:25001", "127.0.0.1:25002"},
143143
},
144144
{
145145
desc: "with instance address",
146146
in: &proxy.Config{
147147
Addr: "1.1.1.1", // bad address, binding shouldn't happen here.
148-
Port: 50003,
148+
Port: 24003,
149149
Instances: []proxy.InstanceConnConfig{
150150
{Addr: "0.0.0.0", Name: pg},
151151
},
152152
},
153-
wantTCPAddrs: []string{"0.0.0.0:50003"},
153+
wantTCPAddrs: []string{"0.0.0.0:24003"},
154154
},
155155
{
156156
desc: "IPv6 support",
157157
in: &proxy.Config{
158158
Addr: "::1",
159-
Port: 50004,
159+
Port: 24004,
160160
Instances: []proxy.InstanceConnConfig{
161161
{Name: pg},
162162
},
163163
},
164-
wantTCPAddrs: []string{"[::1]:50004"},
164+
wantTCPAddrs: []string{"[::1]:24004"},
165165
},
166166
{
167167
desc: "with instance port",
168168
in: &proxy.Config{
169169
Addr: "127.0.0.1",
170-
Port: 50005,
170+
Port: 24005,
171171
Instances: []proxy.InstanceConnConfig{
172-
{Name: pg, Port: 60000},
172+
{Name: pg, Port: 26000},
173173
},
174174
},
175-
wantTCPAddrs: []string{"127.0.0.1:60000"},
175+
wantTCPAddrs: []string{"127.0.0.1:26000"},
176176
},
177177
{
178178
desc: "with global port and instance port",
179179
in: &proxy.Config{
180180
Addr: "127.0.0.1",
181-
Port: 50006,
181+
Port: 24006,
182182
Instances: []proxy.InstanceConnConfig{
183183
{Name: pg},
184-
{Name: mysql, Port: 60001},
184+
{Name: mysql, Port: 26001},
185185
{Name: sqlserver},
186186
},
187187
},
188188
wantTCPAddrs: []string{
189-
"127.0.0.1:50006",
190-
"127.0.0.1:60001",
191-
"127.0.0.1:50007",
189+
"127.0.0.1:24006",
190+
"127.0.0.1:26001",
191+
"127.0.0.1:24007",
192192
},
193193
},
194194
{
@@ -229,7 +229,7 @@ func TestClientInitialization(t *testing.T) {
229229
desc: "with a global TCP host port and an instance Unix socket",
230230
in: &proxy.Config{
231231
Addr: "127.0.0.1",
232-
Port: 50008,
232+
Port: 24008,
233233
Instances: []proxy.InstanceConnConfig{
234234
{Name: mysql, UnixSocket: testDir},
235235
},
@@ -244,11 +244,11 @@ func TestClientInitialization(t *testing.T) {
244244
Addr: "127.0.0.1",
245245
UnixSocket: testDir,
246246
Instances: []proxy.InstanceConnConfig{
247-
{Name: pg, Port: 50009},
247+
{Name: pg, Port: 24009},
248248
},
249249
},
250250
wantTCPAddrs: []string{
251-
"127.0.0.1:50009",
251+
"127.0.0.1:24009",
252252
},
253253
},
254254
{
@@ -326,11 +326,11 @@ func TestClientInitialization(t *testing.T) {
326326
desc: "with TCP port for non functional instance",
327327
in: &proxy.Config{
328328
Instances: []proxy.InstanceConnConfig{
329-
{Name: "proj:region:fakeserver", Port: 51010},
329+
{Name: "proj:region:fakeserver", Port: 25010},
330330
},
331331
},
332332
wantTCPAddrs: []string{
333-
"127.0.0.1:51010",
333+
"127.0.0.1:25010",
334334
},
335335
},
336336
}
@@ -377,7 +377,7 @@ func TestClientLimitsMaxConnections(t *testing.T) {
377377
d := &fakeDialer{}
378378
in := &proxy.Config{
379379
Addr: "127.0.0.1",
380-
Port: 50011,
380+
Port: 24011,
381381
Instances: []proxy.InstanceConnConfig{
382382
{Name: "proj:region:pg"},
383383
},
@@ -396,13 +396,13 @@ func TestClientLimitsMaxConnections(t *testing.T) {
396396
defer c.Close()
397397
go c.Serve(context.Background(), func() {})
398398

399-
conn1, err1 := net.Dial("tcp", "127.0.0.1:50011")
399+
conn1, err1 := net.Dial("tcp", "127.0.0.1:24011")
400400
if err1 != nil {
401401
t.Fatalf("net.Dial error: %v", err1)
402402
}
403403
defer conn1.Close()
404404

405-
conn2, err2 := net.Dial("tcp", "127.0.0.1:50011")
405+
conn2, err2 := net.Dial("tcp", "127.0.0.1:24011")
406406
if err2 != nil {
407407
t.Fatalf("net.Dial error: %v", err1)
408408
}
@@ -459,7 +459,7 @@ func tryTCPDial(t *testing.T, addr string) net.Conn {
459459
func TestClientCloseWaitsForActiveConnections(t *testing.T) {
460460
in := &proxy.Config{
461461
Addr: "127.0.0.1",
462-
Port: 50012,
462+
Port: 24012,
463463
Instances: []proxy.InstanceConnConfig{
464464
{Name: "proj:region:pg"},
465465
},
@@ -471,7 +471,7 @@ func TestClientCloseWaitsForActiveConnections(t *testing.T) {
471471
}
472472
go c.Serve(context.Background(), func() {})
473473

474-
conn := tryTCPDial(t, "127.0.0.1:50012")
474+
conn := tryTCPDial(t, "127.0.0.1:24012")
475475
defer conn.Close()
476476

477477
if err := c.Close(); err == nil {
@@ -482,7 +482,7 @@ func TestClientCloseWaitsForActiveConnections(t *testing.T) {
482482
func TestClientClosesCleanly(t *testing.T) {
483483
in := &proxy.Config{
484484
Addr: "127.0.0.1",
485-
Port: 50013,
485+
Port: 24013,
486486
Instances: []proxy.InstanceConnConfig{
487487
{Name: "proj:reg:inst"},
488488
},
@@ -493,7 +493,7 @@ func TestClientClosesCleanly(t *testing.T) {
493493
}
494494
go c.Serve(context.Background(), func() {})
495495

496-
conn := tryTCPDial(t, "127.0.0.1:50013")
496+
conn := tryTCPDial(t, "127.0.0.1:24013")
497497
_ = conn.Close()
498498

499499
if err := c.Close(); err != nil {
@@ -504,7 +504,7 @@ func TestClientClosesCleanly(t *testing.T) {
504504
func TestClosesWithError(t *testing.T) {
505505
in := &proxy.Config{
506506
Addr: "127.0.0.1",
507-
Port: 50014,
507+
Port: 24014,
508508
Instances: []proxy.InstanceConnConfig{
509509
{Name: "proj:reg:inst"},
510510
},
@@ -515,7 +515,7 @@ func TestClosesWithError(t *testing.T) {
515515
}
516516
go c.Serve(context.Background(), func() {})
517517

518-
conn := tryTCPDial(t, "127.0.0.1:50014")
518+
conn := tryTCPDial(t, "127.0.0.1:24014")
519519
defer conn.Close()
520520

521521
if err = c.Close(); err == nil {
@@ -611,7 +611,7 @@ func TestClientNotifiesCallerOnServe(t *testing.T) {
611611
func TestClientConnCount(t *testing.T) {
612612
in := &proxy.Config{
613613
Addr: "127.0.0.1",
614-
Port: 50015,
614+
Port: 24015,
615615
Instances: []proxy.InstanceConnConfig{
616616
{Name: "proj:region:pg"},
617617
},
@@ -633,7 +633,7 @@ func TestClientConnCount(t *testing.T) {
633633
t.Fatalf("want 10 max connections, got = %v", gotMax)
634634
}
635635

636-
conn := tryTCPDial(t, "127.0.0.1:50015")
636+
conn := tryTCPDial(t, "127.0.0.1:24015")
637637
defer conn.Close()
638638

639639
verifyOpen := func(t *testing.T, want uint64) {
@@ -653,7 +653,7 @@ func TestClientConnCount(t *testing.T) {
653653
func TestCheckConnections(t *testing.T) {
654654
in := &proxy.Config{
655655
Addr: "127.0.0.1",
656-
Port: 50016,
656+
Port: 24016,
657657
Instances: []proxy.InstanceConnConfig{
658658
{Name: "proj:region:pg"},
659659
},
@@ -680,7 +680,7 @@ func TestCheckConnections(t *testing.T) {
680680

681681
in = &proxy.Config{
682682
Addr: "127.0.0.1",
683-
Port: 60002,
683+
Port: 26002,
684684
Instances: []proxy.InstanceConnConfig{
685685
{Name: "proj:region:pg1"},
686686
{Name: "proj:region:pg2"},
@@ -706,7 +706,7 @@ func TestCheckConnections(t *testing.T) {
706706
func TestRunConnectionCheck(t *testing.T) {
707707
in := &proxy.Config{
708708
Addr: "127.0.0.1",
709-
Port: 50017,
709+
Port: 24017,
710710
Instances: []proxy.InstanceConnConfig{
711711
{Name: "proj:region:pg"},
712712
},
@@ -815,8 +815,8 @@ func TestProxyMultiInstances(t *testing.T) {
815815
desc: "with two tcp socket instances and conflicting ports",
816816
in: &proxy.Config{
817817
Instances: []proxy.InstanceConnConfig{
818-
{Name: "proj:region:fakeserver", Port: 60003},
819-
{Name: mysql, Port: 60003},
818+
{Name: "proj:region:fakeserver", Port: 26003},
819+
{Name: mysql, Port: 26003},
820820
},
821821
},
822822
wantSuccess: false,

0 commit comments

Comments
 (0)