Skip to content

Commit

Permalink
chore: update tests to use unique ports (#2280)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackwotherspoon authored Jul 29, 2024
1 parent 4cfa6a2 commit 5ff61de
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions internal/proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,29 +146,29 @@ func TestClientInitialization(t *testing.T) {
desc: "with instance address",
in: &proxy.Config{
Addr: "1.1.1.1", // bad address, binding shouldn't happen here.
Port: 50000,
Port: 50003,
Instances: []proxy.InstanceConnConfig{
{Addr: "0.0.0.0", Name: pg},
},
},
wantTCPAddrs: []string{"0.0.0.0:50000"},
wantTCPAddrs: []string{"0.0.0.0:50003"},
},
{
desc: "IPv6 support",
in: &proxy.Config{
Addr: "::1",
Port: 50000,
Port: 50004,
Instances: []proxy.InstanceConnConfig{
{Name: pg},
},
},
wantTCPAddrs: []string{"[::1]:50000"},
wantTCPAddrs: []string{"[::1]:50004"},
},
{
desc: "with instance port",
in: &proxy.Config{
Addr: "127.0.0.1",
Port: 50000,
Port: 50005,
Instances: []proxy.InstanceConnConfig{
{Name: pg, Port: 60000},
},
Expand All @@ -179,17 +179,17 @@ func TestClientInitialization(t *testing.T) {
desc: "with global port and instance port",
in: &proxy.Config{
Addr: "127.0.0.1",
Port: 50000,
Port: 50006,
Instances: []proxy.InstanceConnConfig{
{Name: pg},
{Name: mysql, Port: 60000},
{Name: mysql, Port: 60001},
{Name: sqlserver},
},
},
wantTCPAddrs: []string{
"127.0.0.1:50000",
"127.0.0.1:60000",
"127.0.0.1:50001",
"127.0.0.1:50006",
"127.0.0.1:60001",
"127.0.0.1:50007",
},
},
{
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestClientInitialization(t *testing.T) {
desc: "with a global TCP host port and an instance Unix socket",
in: &proxy.Config{
Addr: "127.0.0.1",
Port: 50000,
Port: 50008,
Instances: []proxy.InstanceConnConfig{
{Name: mysql, UnixSocket: testDir},
},
Expand All @@ -245,11 +245,11 @@ func TestClientInitialization(t *testing.T) {
Addr: "127.0.0.1",
UnixSocket: testDir,
Instances: []proxy.InstanceConnConfig{
{Name: pg, Port: 50000},
{Name: pg, Port: 50009},
},
},
wantTCPAddrs: []string{
"127.0.0.1:50000",
"127.0.0.1:50009",
},
},
{
Expand Down Expand Up @@ -313,11 +313,11 @@ func TestClientInitialization(t *testing.T) {
desc: "with TCP port for non functional instance",
in: &proxy.Config{
Instances: []proxy.InstanceConnConfig{
{Name: "proj:region:fakeserver", Port: 50000},
{Name: "proj:region:fakeserver", Port: 50010},
},
},
wantTCPAddrs: []string{
"127.0.0.1:50000",
"127.0.0.1:50010",
},
},
}
Expand Down Expand Up @@ -364,7 +364,7 @@ func TestClientLimitsMaxConnections(t *testing.T) {
d := &fakeDialer{}
in := &proxy.Config{
Addr: "127.0.0.1",
Port: 50000,
Port: 50011,
Instances: []proxy.InstanceConnConfig{
{Name: "proj:region:pg"},
},
Expand All @@ -377,13 +377,13 @@ func TestClientLimitsMaxConnections(t *testing.T) {
defer c.Close()
go c.Serve(context.Background(), func() {})

conn1, err1 := net.Dial("tcp", "127.0.0.1:50000")
conn1, err1 := net.Dial("tcp", "127.0.0.1:50011")
if err1 != nil {
t.Fatalf("net.Dial error: %v", err1)
}
defer conn1.Close()

conn2, err2 := net.Dial("tcp", "127.0.0.1:50000")
conn2, err2 := net.Dial("tcp", "127.0.0.1:50011")
if err2 != nil {
t.Fatalf("net.Dial error: %v", err1)
}
Expand Down Expand Up @@ -436,7 +436,7 @@ func tryTCPDial(t *testing.T, addr string) net.Conn {
func TestClientCloseWaitsForActiveConnections(t *testing.T) {
in := &proxy.Config{
Addr: "127.0.0.1",
Port: 50000,
Port: 50012,
Instances: []proxy.InstanceConnConfig{
{Name: "proj:region:pg"},
},
Expand All @@ -448,7 +448,7 @@ func TestClientCloseWaitsForActiveConnections(t *testing.T) {
}
go c.Serve(context.Background(), func() {})

conn := tryTCPDial(t, "127.0.0.1:50000")
conn := tryTCPDial(t, "127.0.0.1:50012")
defer conn.Close()

if err := c.Close(); err == nil {
Expand All @@ -459,7 +459,7 @@ func TestClientCloseWaitsForActiveConnections(t *testing.T) {
func TestClientClosesCleanly(t *testing.T) {
in := &proxy.Config{
Addr: "127.0.0.1",
Port: 50000,
Port: 50013,
Instances: []proxy.InstanceConnConfig{
{Name: "proj:reg:inst"},
},
Expand All @@ -470,7 +470,7 @@ func TestClientClosesCleanly(t *testing.T) {
}
go c.Serve(context.Background(), func() {})

conn := tryTCPDial(t, "127.0.0.1:50000")
conn := tryTCPDial(t, "127.0.0.1:50013")
_ = conn.Close()

if err := c.Close(); err != nil {
Expand All @@ -481,7 +481,7 @@ func TestClientClosesCleanly(t *testing.T) {
func TestClosesWithError(t *testing.T) {
in := &proxy.Config{
Addr: "127.0.0.1",
Port: 50000,
Port: 50014,
Instances: []proxy.InstanceConnConfig{
{Name: "proj:reg:inst"},
},
Expand All @@ -492,7 +492,7 @@ func TestClosesWithError(t *testing.T) {
}
go c.Serve(context.Background(), func() {})

conn := tryTCPDial(t, "127.0.0.1:50000")
conn := tryTCPDial(t, "127.0.0.1:50014")
defer conn.Close()

if err = c.Close(); err == nil {
Expand Down Expand Up @@ -588,7 +588,7 @@ func TestClientNotifiesCallerOnServe(t *testing.T) {
func TestClientConnCount(t *testing.T) {
in := &proxy.Config{
Addr: "127.0.0.1",
Port: 50000,
Port: 50015,
Instances: []proxy.InstanceConnConfig{
{Name: "proj:region:pg"},
},
Expand All @@ -610,7 +610,7 @@ func TestClientConnCount(t *testing.T) {
t.Fatalf("want 10 max connections, got = %v", gotMax)
}

conn := tryTCPDial(t, "127.0.0.1:50000")
conn := tryTCPDial(t, "127.0.0.1:50015")
defer conn.Close()

verifyOpen := func(t *testing.T, want uint64) {
Expand All @@ -630,7 +630,7 @@ func TestClientConnCount(t *testing.T) {
func TestCheckConnections(t *testing.T) {
in := &proxy.Config{
Addr: "127.0.0.1",
Port: 50000,
Port: 50016,
Instances: []proxy.InstanceConnConfig{
{Name: "proj:region:pg"},
},
Expand All @@ -657,7 +657,7 @@ func TestCheckConnections(t *testing.T) {

in = &proxy.Config{
Addr: "127.0.0.1",
Port: 60000,
Port: 60002,
Instances: []proxy.InstanceConnConfig{
{Name: "proj:region:pg1"},
{Name: "proj:region:pg2"},
Expand All @@ -683,7 +683,7 @@ func TestCheckConnections(t *testing.T) {
func TestRunConnectionCheck(t *testing.T) {
in := &proxy.Config{
Addr: "127.0.0.1",
Port: 50002,
Port: 50017,
Instances: []proxy.InstanceConnConfig{
{Name: "proj:region:pg"},
},
Expand Down Expand Up @@ -792,8 +792,8 @@ func TestProxyMultiInstances(t *testing.T) {
desc: "with two tcp socket instances and conflicting ports",
in: &proxy.Config{
Instances: []proxy.InstanceConnConfig{
{Name: "proj:region:fakeserver", Port: 60000},
{Name: mysql, Port: 60000},
{Name: "proj:region:fakeserver", Port: 60003},
{Name: mysql, Port: 60003},
},
},
wantSuccess: false,
Expand Down

0 comments on commit 5ff61de

Please sign in to comment.