fix test bind

pull/412/head
Tony 5 years ago
parent 9155dbfe6b
commit 0f7fb0e66d
  1. 6
      pkg/net/rpc/warden/resolver/direct/test/direct_test.go
  2. 19
      pkg/net/rpc/warden/server_test.go

@ -42,8 +42,8 @@ func createServer(name, listen string) *warden.Server {
func TestMain(m *testing.M) {
resolver.Register(direct.New())
ctx := context.TODO()
s1 := createServer("server1", "127.0.0.1:18081")
s2 := createServer("server2", "127.0.0.1:18082")
s1 := createServer("server1", "127.0.0.1:18001")
s2 := createServer("server2", "127.0.0.1:18002")
defer s1.Shutdown(ctx)
defer s2.Shutdown(ctx)
os.Exit(m.Run())
@ -68,7 +68,7 @@ func createTestClient(t *testing.T, connStr string) pb.GreeterClient {
}
func TestDirect(t *testing.T) {
cli := createTestClient(t, "direct://default/127.0.0.1:18083,127.0.0.1:18082")
cli := createTestClient(t, "direct://default/127.0.0.1:18003,127.0.0.1:18002")
count := 0
for i := 0; i < 10; i++ {
if resp, err := cli.SayHello(context.TODO(), &pb.HelloRequest{Age: 1, Name: "hello"}); err != nil {

@ -30,6 +30,8 @@ import (
const (
_separator = "\001"
_testAddr = "127.0.0.1:9090"
)
var (
@ -156,7 +158,7 @@ func (s *helloServer) StreamHello(ss pb.Greeter_StreamHelloServer) error {
func runServer(t *testing.T, interceptors ...grpc.UnaryServerInterceptor) func() {
return func() {
server = NewServer(&ServerConfig{Addr: "127.0.0.1:8080", Timeout: xtime.Duration(time.Second)})
server = NewServer(&ServerConfig{Addr: _testAddr, Timeout: xtime.Duration(time.Second)})
pb.RegisterGreeterServer(server.Server(), &helloServer{t})
server.Use(
func(ctx context.Context, req interface{}, args *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
@ -180,7 +182,7 @@ func runServer(t *testing.T, interceptors ...grpc.UnaryServerInterceptor) func()
func runClient(ctx context.Context, cc *ClientConfig, t *testing.T, name string, age int32, interceptors ...grpc.UnaryClientInterceptor) (resp *pb.HelloReply, err error) {
client := NewClient(cc)
client.Use(interceptors...)
conn, err := client.Dial(context.Background(), "127.0.0.1:8080")
conn, err := client.Dial(context.Background(), _testAddr)
if err != nil {
panic(fmt.Errorf("did not connect: %v,req: %v %v", err, name, age))
}
@ -226,7 +228,7 @@ func testTimeoutOpt(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*100)
defer cancel()
client := NewClient(&clientConfig)
conn, err := client.Dial(ctx, "127.0.0.1:8080")
conn, err := client.Dial(ctx, _testAddr)
if err != nil {
t.Fatalf("did not connect: %v", err)
}
@ -284,7 +286,7 @@ func testAllErrorCase(t *testing.T) {
func testBreaker(t *testing.T) {
client := NewClient(&clientConfig)
conn, err := client.Dial(context.Background(), "127.0.0.1:8080")
conn, err := client.Dial(context.Background(), _testAddr)
if err != nil {
t.Fatalf("did not connect: %v", err)
}
@ -378,7 +380,7 @@ func testClientRecovery(t *testing.T) {
panic("client recovery test")
})
conn, err := client.Dial(ctx, "127.0.0.1:8080")
conn, err := client.Dial(ctx, _testAddr)
if err != nil {
t.Fatalf("did not connect: %v", err)
}
@ -403,7 +405,7 @@ func testServerRecovery(t *testing.T) {
ctx := context.Background()
client := NewClient(&clientConfig)
conn, err := client.Dial(ctx, "127.0.0.1:8080")
conn, err := client.Dial(ctx, _testAddr)
if err != nil {
t.Fatalf("did not connect: %v", err)
}
@ -491,7 +493,7 @@ func testTrace(t *testing.T, port int, isStream bool) {
}
func BenchmarkServer(b *testing.B) {
server := NewServer(&ServerConfig{Addr: "127.0.0.1:8080", Timeout: xtime.Duration(time.Second)})
server := NewServer(&ServerConfig{Addr: _testAddr, Timeout: xtime.Duration(time.Second)})
go func() {
pb.RegisterGreeterServer(server.Server(), &helloServer{})
if _, err := server.Start(); err != nil {
@ -503,7 +505,7 @@ func BenchmarkServer(b *testing.B) {
server.Server().Stop()
}()
client := NewClient(&clientConfig)
conn, err := client.Dial(context.Background(), "127.0.0.1:8080")
conn, err := client.Dial(context.Background(), _testAddr)
if err != nil {
conn.Close()
b.Fatalf("did not connect: %v", err)
@ -602,4 +604,3 @@ func TestStartWithAddr(t *testing.T) {
assert.Nil(t, err)
}
}

Loading…
Cancel
Save