Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add TestEtcdGrpcResolverWithMetaInfo for #19700 #19702

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 41 additions & 9 deletions tests/integration/clientv3/naming/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
testpb "google.golang.org/grpc/interop/grpc_testing"

"go.etcd.io/etcd/client/v3/naming/endpoints"
"go.etcd.io/etcd/client/v3/naming/resolver"
"go.etcd.io/etcd/pkg/v3/grpctesting"
integration2 "go.etcd.io/etcd/tests/v3/framework/integration"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
testpb "google.golang.org/grpc/interop/grpc_testing"
)

func testEtcdGRPCResolver(t *testing.T, lbPolicy string) {
func testEtcdGRPCResolver(t *testing.T, lbPolicy string, meta any) {
// Setup two new dummy stub servers
payloadBody := []byte{'1'}
s1 := grpctesting.NewDummyStubServer(payloadBody)
Expand All @@ -57,8 +56,14 @@ func testEtcdGRPCResolver(t *testing.T, lbPolicy string) {
t.Fatal("failed to create EndpointManager", err)
}

e1 := endpoints.Endpoint{Addr: s1.Addr()}
e2 := endpoints.Endpoint{Addr: s2.Addr()}
e1 := endpoints.Endpoint{
Addr: s1.Addr(),
Metadata: meta,
}
e2 := endpoints.Endpoint{
Addr: s2.Addr(),
Metadata: meta,
}

err = em.AddEndpoint(context.TODO(), "foo/e1", e1)
if err != nil {
Expand Down Expand Up @@ -130,15 +135,42 @@ func TestEtcdGrpcResolverPickFirst(t *testing.T) {
integration2.BeforeTest(t)

// Pick first is the default load balancer policy for grpc-go
testEtcdGRPCResolver(t, "pick_first")
testEtcdGRPCResolver(t, "pick_first", nil)
}

// TestEtcdGrpcResolverRoundRobin mimics scenarios described in grpc_naming.md doc.
func TestEtcdGrpcResolverRoundRobin(t *testing.T) {
integration2.BeforeTest(t)

// Round robin is a common alternative for more production oriented scenarios
testEtcdGRPCResolver(t, "round_robin")
testEtcdGRPCResolver(t, "round_robin", nil)
}

type testMetaInfo struct {
ServerName string
Metadata any
}

// TestEtcdGrpcResolverPickFirstWithMetaInfo mimics scenarios described in grpc_naming.md doc.
func TestEtcdGrpcResolverPickFirstWithMetaInfo(t *testing.T) {
integration2.BeforeTest(t)

// Pick first is the default load balancer policy for grpc-go
testEtcdGRPCResolver(t, "pick_first", &testMetaInfo{
ServerName: "s1",
Metadata: "testMeta",
})
}

// TestEtcdGrpcResolverRoundRobinWithMetaInfo mimics scenarios described in grpc_naming.md doc.
func TestEtcdGrpcResolverRoundRobinWithMetaInfo(t *testing.T) {
integration2.BeforeTest(t)

// Round robin is a common alternative for more production oriented scenarios
testEtcdGRPCResolver(t, "round_robin", &testMetaInfo{
ServerName: "s1",
Metadata: "testMeta",
})
}

func TestEtcdEndpointManager(t *testing.T) {
Expand Down