replace 127.0.0.1 with localhost for ipv6 only environment (#1306)
This commit is contained in:
@ -97,7 +97,7 @@ func startServers(t *testing.T, numServers int, maxStreams uint32) ([]*server, *
|
|||||||
s.wait(t, 2*time.Second)
|
s.wait(t, 2*time.Second)
|
||||||
}
|
}
|
||||||
// Point to server[0]
|
// Point to server[0]
|
||||||
addr := "127.0.0.1:" + servers[0].port
|
addr := "localhost:" + servers[0].port
|
||||||
return servers, &testNameResolver{
|
return servers, &testNameResolver{
|
||||||
addr: addr,
|
addr: addr,
|
||||||
}
|
}
|
||||||
@ -120,11 +120,11 @@ func TestNameDiscovery(t *testing.T) {
|
|||||||
var updates []*naming.Update
|
var updates []*naming.Update
|
||||||
updates = append(updates, &naming.Update{
|
updates = append(updates, &naming.Update{
|
||||||
Op: naming.Delete,
|
Op: naming.Delete,
|
||||||
Addr: "127.0.0.1:" + servers[0].port,
|
Addr: "localhost:" + servers[0].port,
|
||||||
})
|
})
|
||||||
updates = append(updates, &naming.Update{
|
updates = append(updates, &naming.Update{
|
||||||
Op: naming.Add,
|
Op: naming.Add,
|
||||||
Addr: "127.0.0.1:" + servers[1].port,
|
Addr: "localhost:" + servers[1].port,
|
||||||
})
|
})
|
||||||
r.w.inject(updates)
|
r.w.inject(updates)
|
||||||
// Loop until the rpcs in flight talks to servers[1].
|
// Loop until the rpcs in flight talks to servers[1].
|
||||||
@ -154,7 +154,7 @@ func TestEmptyAddrs(t *testing.T) {
|
|||||||
// available after that.
|
// available after that.
|
||||||
u := &naming.Update{
|
u := &naming.Update{
|
||||||
Op: naming.Delete,
|
Op: naming.Delete,
|
||||||
Addr: "127.0.0.1:" + servers[0].port,
|
Addr: "localhost:" + servers[0].port,
|
||||||
}
|
}
|
||||||
r.w.inject([]*naming.Update{u})
|
r.w.inject([]*naming.Update{u})
|
||||||
// Loop until the above updates apply.
|
// Loop until the above updates apply.
|
||||||
@ -180,7 +180,7 @@ func TestRoundRobin(t *testing.T) {
|
|||||||
// Add servers[1] to the service discovery.
|
// Add servers[1] to the service discovery.
|
||||||
u := &naming.Update{
|
u := &naming.Update{
|
||||||
Op: naming.Add,
|
Op: naming.Add,
|
||||||
Addr: "127.0.0.1:" + servers[1].port,
|
Addr: "localhost:" + servers[1].port,
|
||||||
}
|
}
|
||||||
r.w.inject([]*naming.Update{u})
|
r.w.inject([]*naming.Update{u})
|
||||||
req := "port"
|
req := "port"
|
||||||
@ -195,7 +195,7 @@ func TestRoundRobin(t *testing.T) {
|
|||||||
// Add server2[2] to the service discovery.
|
// Add server2[2] to the service discovery.
|
||||||
u = &naming.Update{
|
u = &naming.Update{
|
||||||
Op: naming.Add,
|
Op: naming.Add,
|
||||||
Addr: "127.0.0.1:" + servers[2].port,
|
Addr: "localhost:" + servers[2].port,
|
||||||
}
|
}
|
||||||
r.w.inject([]*naming.Update{u})
|
r.w.inject([]*naming.Update{u})
|
||||||
// Loop until both servers[2] are up.
|
// Loop until both servers[2] are up.
|
||||||
@ -230,7 +230,7 @@ func TestCloseWithPendingRPC(t *testing.T) {
|
|||||||
// Remove the server.
|
// Remove the server.
|
||||||
updates := []*naming.Update{{
|
updates := []*naming.Update{{
|
||||||
Op: naming.Delete,
|
Op: naming.Delete,
|
||||||
Addr: "127.0.0.1:" + servers[0].port,
|
Addr: "localhost:" + servers[0].port,
|
||||||
}}
|
}}
|
||||||
r.w.inject(updates)
|
r.w.inject(updates)
|
||||||
// Loop until the above update applies.
|
// Loop until the above update applies.
|
||||||
@ -274,7 +274,7 @@ func TestGetOnWaitChannel(t *testing.T) {
|
|||||||
// Remove all servers so that all upcoming RPCs will block on waitCh.
|
// Remove all servers so that all upcoming RPCs will block on waitCh.
|
||||||
updates := []*naming.Update{{
|
updates := []*naming.Update{{
|
||||||
Op: naming.Delete,
|
Op: naming.Delete,
|
||||||
Addr: "127.0.0.1:" + servers[0].port,
|
Addr: "localhost:" + servers[0].port,
|
||||||
}}
|
}}
|
||||||
r.w.inject(updates)
|
r.w.inject(updates)
|
||||||
for {
|
for {
|
||||||
@ -297,7 +297,7 @@ func TestGetOnWaitChannel(t *testing.T) {
|
|||||||
// Add a connected server to get the above RPC through.
|
// Add a connected server to get the above RPC through.
|
||||||
updates = []*naming.Update{{
|
updates = []*naming.Update{{
|
||||||
Op: naming.Add,
|
Op: naming.Add,
|
||||||
Addr: "127.0.0.1:" + servers[0].port,
|
Addr: "localhost:" + servers[0].port,
|
||||||
}}
|
}}
|
||||||
r.w.inject(updates)
|
r.w.inject(updates)
|
||||||
// Wait until the above RPC succeeds.
|
// Wait until the above RPC succeeds.
|
||||||
@ -318,7 +318,7 @@ func TestOneServerDown(t *testing.T) {
|
|||||||
var updates []*naming.Update
|
var updates []*naming.Update
|
||||||
updates = append(updates, &naming.Update{
|
updates = append(updates, &naming.Update{
|
||||||
Op: naming.Add,
|
Op: naming.Add,
|
||||||
Addr: "127.0.0.1:" + servers[1].port,
|
Addr: "localhost:" + servers[1].port,
|
||||||
})
|
})
|
||||||
r.w.inject(updates)
|
r.w.inject(updates)
|
||||||
req := "port"
|
req := "port"
|
||||||
@ -372,7 +372,7 @@ func TestOneAddressRemoval(t *testing.T) {
|
|||||||
var updates []*naming.Update
|
var updates []*naming.Update
|
||||||
updates = append(updates, &naming.Update{
|
updates = append(updates, &naming.Update{
|
||||||
Op: naming.Add,
|
Op: naming.Add,
|
||||||
Addr: "127.0.0.1:" + servers[1].port,
|
Addr: "localhost:" + servers[1].port,
|
||||||
})
|
})
|
||||||
r.w.inject(updates)
|
r.w.inject(updates)
|
||||||
req := "port"
|
req := "port"
|
||||||
@ -395,7 +395,7 @@ func TestOneAddressRemoval(t *testing.T) {
|
|||||||
var updates []*naming.Update
|
var updates []*naming.Update
|
||||||
updates = append(updates, &naming.Update{
|
updates = append(updates, &naming.Update{
|
||||||
Op: naming.Delete,
|
Op: naming.Delete,
|
||||||
Addr: "127.0.0.1:" + servers[0].port,
|
Addr: "localhost:" + servers[0].port,
|
||||||
})
|
})
|
||||||
r.w.inject(updates)
|
r.w.inject(updates)
|
||||||
wg.Done()
|
wg.Done()
|
||||||
|
@ -24,7 +24,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
@ -46,8 +45,8 @@ var (
|
|||||||
besn = "foo.com"
|
besn = "foo.com"
|
||||||
lbToken = "iamatoken"
|
lbToken = "iamatoken"
|
||||||
|
|
||||||
// Resolver replaces 127.0.0.1 with fakeName in Next().
|
// Resolver replaces localhost with fakeName in Next().
|
||||||
// Dialer replaces fakeName with 127.0.0.1 when dialing.
|
// Dialer replaces fakeName with localhost when dialing.
|
||||||
// This will test that custom dialer is passed from Dial to grpclb.
|
// This will test that custom dialer is passed from Dial to grpclb.
|
||||||
fakeName = "fake.Name"
|
fakeName = "fake.Name"
|
||||||
)
|
)
|
||||||
@ -72,9 +71,9 @@ func (w *testWatcher) Next() (updates []*naming.Update, err error) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
if u != nil {
|
if u != nil {
|
||||||
// Resolver replaces 127.0.0.1 with fakeName in Next().
|
// Resolver replaces localhost with fakeName in Next().
|
||||||
// Custom dialer will replace fakeName with 127.0.0.1 when dialing.
|
// Custom dialer will replace fakeName with localhost when dialing.
|
||||||
u.Addr = strings.Replace(u.Addr, "127.0.0.1", fakeName, 1)
|
u.Addr = strings.Replace(u.Addr, "localhost", fakeName, 1)
|
||||||
updates = append(updates, u)
|
updates = append(updates, u)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -174,10 +173,10 @@ func (c *serverNameCheckCreds) OverrideServerName(s string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// fakeNameDialer replaces fakeName with 127.0.0.1 when dialing.
|
// fakeNameDialer replaces fakeName with localhost when dialing.
|
||||||
// This will test that custom dialer is passed from Dial to grpclb.
|
// This will test that custom dialer is passed from Dial to grpclb.
|
||||||
func fakeNameDialer(addr string, timeout time.Duration) (net.Conn, error) {
|
func fakeNameDialer(addr string, timeout time.Duration) (net.Conn, error) {
|
||||||
addr = strings.Replace(addr, fakeName, "127.0.0.1", 1)
|
addr = strings.Replace(addr, fakeName, "localhost", 1)
|
||||||
return net.DialTimeout("tcp", addr, timeout)
|
return net.DialTimeout("tcp", addr, timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,10 +326,7 @@ func newLoadBalancer(numberOfBackends int) (tss *testServers, cleanup func(), er
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
beIPs = append(beIPs, beLis.Addr().(*net.TCPAddr).IP)
|
beIPs = append(beIPs, beLis.Addr().(*net.TCPAddr).IP)
|
||||||
|
bePorts = append(bePorts, beLis.Addr().(*net.TCPAddr).Port)
|
||||||
beAddr := strings.Split(beLis.Addr().String(), ":")
|
|
||||||
bePort, _ := strconv.Atoi(beAddr[1])
|
|
||||||
bePorts = append(bePorts, bePort)
|
|
||||||
|
|
||||||
beListeners = append(beListeners, beLis)
|
beListeners = append(beListeners, beLis)
|
||||||
}
|
}
|
||||||
|
@ -215,14 +215,9 @@ func (te *test) startServer(ts testpb.TestServiceServer) {
|
|||||||
if te.testServer != nil {
|
if te.testServer != nil {
|
||||||
testpb.RegisterTestServiceServer(s, te.testServer)
|
testpb.RegisterTestServiceServer(s, te.testServer)
|
||||||
}
|
}
|
||||||
_, port, err := net.SplitHostPort(lis.Addr().String())
|
|
||||||
if err != nil {
|
|
||||||
te.t.Fatalf("Failed to parse listener address: %v", err)
|
|
||||||
}
|
|
||||||
addr := "127.0.0.1:" + port
|
|
||||||
|
|
||||||
go s.Serve(lis)
|
go s.Serve(lis)
|
||||||
te.srvAddr = addr
|
te.srvAddr = lis.Addr().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (te *test) clientConn() *grpc.ClientConn {
|
func (te *test) clientConn() *grpc.ClientConn {
|
||||||
|
Reference in New Issue
Block a user