Skip to content

Commit f549da3

Browse files
committed
backport #12709 and #12801 to resolve gogo unmarshal errors
Signed-off-by: Chao Chen <chaochn@amazon.com>
1 parent 1665b8e commit f549da3

3 files changed

Lines changed: 28 additions & 37 deletions

File tree

clientv3/integration/naming/resolver_test.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"go.etcd.io/etcd/clientv3/naming/endpoints"
2727
"go.etcd.io/etcd/clientv3/naming/resolver"
2828
"go.etcd.io/etcd/integration"
29-
grpctest "go.etcd.io/etcd/pkg/grpc_testing"
29+
"go.etcd.io/etcd/pkg/grpc_testing"
3030
"go.etcd.io/etcd/pkg/testutil"
3131
)
3232

@@ -35,14 +35,14 @@ import (
3535
func TestEtcdGrpcResolver(t *testing.T) {
3636
defer testutil.AfterTest(t)
3737
s1PayloadBody := []byte{'1'}
38-
s1 := newDummyStubServer(s1PayloadBody)
38+
s1 := grpc_testing.NewDummyStubServer(s1PayloadBody)
3939
if err := s1.Start(nil); err != nil {
4040
t.Fatal("failed to start dummy grpc server (s1)", err)
4141
}
4242
defer s1.Stop()
4343

4444
s2PayloadBody := []byte{'2'}
45-
s2 := newDummyStubServer(s2PayloadBody)
45+
s2 := grpc_testing.NewDummyStubServer(s2PayloadBody)
4646
if err := s2.Start(nil); err != nil {
4747
t.Fatal("failed to start dummy grpc server (s2)", err)
4848
}
@@ -111,16 +111,3 @@ func TestEtcdGrpcResolver(t *testing.T) {
111111
break
112112
}
113113
}
114-
115-
func newDummyStubServer(body []byte) *grpctest.StubServer {
116-
return &grpctest.StubServer{
117-
UnaryCallF: func(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
118-
return &testpb.SimpleResponse{
119-
Payload: &testpb.Payload{
120-
Type: testpb.PayloadType_COMPRESSABLE,
121-
Body: body,
122-
},
123-
}, nil
124-
},
125-
}
126-
}

etcdserver/api/v3rpc/codec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
package v3rpc
1616

17-
import "github.com/gogo/protobuf/proto"
17+
import "github.com/golang/protobuf/proto"
1818

1919
type codec struct{}
2020

pkg/grpc_testing/stub_server.go

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@ import (
3131
// StubServer is a server that is easy to customize within individual test
3232
// cases.
3333
type StubServer struct {
34-
// Guarantees we satisfy this interface; panics if unimplemented methods are called.
35-
testpb.TestServiceServer
36-
37-
EmptyCallF func(ctx context.Context, in *testpb.Empty) (*testpb.Empty, error)
38-
UnaryCallF func(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error)
39-
FullDuplexCallF func(stream testpb.TestService_FullDuplexCallServer) error
34+
testService testpb.TestServiceServer
4035

4136
s *grpc.Server
4237

@@ -47,19 +42,8 @@ type StubServer struct {
4742
cleanups []func() // Lambdas executed in Stop(); populated by Start().
4843
}
4944

50-
// EmptyCall is the handler for testpb.EmptyCall.
51-
func (ss *StubServer) EmptyCall(ctx context.Context, in *testpb.Empty) (*testpb.Empty, error) {
52-
return ss.EmptyCallF(ctx, in)
53-
}
54-
55-
// UnaryCall is the handler for testpb.UnaryCall.
56-
func (ss *StubServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
57-
return ss.UnaryCallF(ctx, in)
58-
}
59-
60-
// FullDuplexCall is the handler for testpb.FullDuplexCall.
61-
func (ss *StubServer) FullDuplexCall(stream testpb.TestService_FullDuplexCallServer) error {
62-
return ss.FullDuplexCallF(stream)
45+
func New(testService testpb.TestServiceServer) *StubServer {
46+
return &StubServer{testService: testService}
6347
}
6448

6549
// Start starts the server and creates a client connected to it.
@@ -79,7 +63,7 @@ func (ss *StubServer) Start(sopts []grpc.ServerOption, dopts ...grpc.DialOption)
7963
ss.cleanups = append(ss.cleanups, func() { lis.Close() })
8064

8165
s := grpc.NewServer(sopts...)
82-
testpb.RegisterTestServiceServer(s, ss)
66+
testpb.RegisterTestServiceServer(s, ss.testService)
8367
go s.Serve(lis)
8468
ss.cleanups = append(ss.cleanups, s.Stop)
8569
ss.s = s
@@ -98,3 +82,23 @@ func (ss *StubServer) Stop() {
9882
func (ss *StubServer) Addr() string {
9983
return ss.Address
10084
}
85+
86+
type dummyStubServer struct {
87+
testpb.UnimplementedTestServiceServer
88+
body []byte
89+
}
90+
91+
func (d dummyStubServer) UnaryCall(context.Context, *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
92+
return &testpb.SimpleResponse{
93+
Payload: &testpb.Payload{
94+
Type: testpb.PayloadType_COMPRESSABLE,
95+
Body: d.body,
96+
},
97+
}, nil
98+
}
99+
100+
// NewDummyStubServer creates a simple test server that serves Unary calls with
101+
// responses with the given payload.
102+
func NewDummyStubServer(body []byte) *StubServer {
103+
return New(dummyStubServer{body: body})
104+
}

0 commit comments

Comments
 (0)