@@ -23,7 +23,6 @@ import (
2323 "errors"
2424 "fmt"
2525 "strings"
26- "sync"
2726 "sync/atomic"
2827 "testing"
2928 "time"
@@ -86,39 +85,19 @@ func (s) TestDuplicateCompressorRegister(t *testing.T) {
8685// errProtoCodec wraps the proto codec and delegates to it if it is configured
8786// to return a nil error. Else, it returns the configured error.
8887type errProtoCodec struct {
89- name string
90-
91- mu sync.Mutex
88+ name string
9289 encodingErr error
9390 decodingErr error
9491}
9592
96- func (c * errProtoCodec ) setEncodingErr (err error ) {
97- c .mu .Lock ()
98- c .encodingErr = err
99- c .mu .Unlock ()
100- }
101-
102- func (c * errProtoCodec ) setDecodingErr (err error ) {
103- c .mu .Lock ()
104- c .decodingErr = err
105- c .mu .Unlock ()
106- }
107-
10893func (c * errProtoCodec ) Marshal (v any ) ([]byte , error ) {
109- c .mu .Lock ()
110- defer c .mu .Unlock ()
111-
11294 if c .encodingErr != nil {
11395 return nil , c .encodingErr
11496 }
11597 return encoding .GetCodec (proto .Name ).Marshal (v )
11698}
11799
118100func (c * errProtoCodec ) Unmarshal (data []byte , v any ) error {
119- c .mu .Lock ()
120- defer c .mu .Unlock ()
121-
122101 if c .decodingErr != nil {
123102 return c .decodingErr
124103 }
@@ -161,7 +140,7 @@ func (s) TestEncodeDoesntPanicOnServer(t *testing.T) {
161140
162141 // Configure the codec on the server to not return errors anymore and expect
163142 // the RPC to succeed.
164- ec .setEncodingErr ( nil )
143+ ec .encodingErr = nil
165144 if _ , err := client .EmptyCall (ctx , & testpb.Empty {}); err != nil {
166145 t .Fatalf ("RPC failed with error: %v" , err )
167146 }
@@ -198,7 +177,7 @@ func (s) TestDecodeDoesntPanicOnServer(t *testing.T) {
198177
199178 // Configure the codec on the server to not return errors anymore and expect
200179 // the RPC to succeed.
201- ec .setDecodingErr ( nil )
180+ ec .decodingErr = nil
202181 if _ , err := client .EmptyCall (ctx , & testpb.Empty {}); err != nil {
203182 t .Fatalf ("RPC failed with error: %v" , err )
204183 }
@@ -234,7 +213,7 @@ func (s) TestEncodeDoesntPanicOnClient(t *testing.T) {
234213
235214 // Configure the codec on the client to not return errors anymore and expect
236215 // the RPC to succeed.
237- ec .setEncodingErr ( nil )
216+ ec .encodingErr = nil
238217 if _ , err := client .EmptyCall (ctx , & testpb.Empty {}, grpc .ForceCodec (ec )); err != nil {
239218 t .Fatalf ("RPC failed with error: %v" , err )
240219 }
@@ -270,7 +249,7 @@ func (s) TestDecodeDoesntPanicOnClient(t *testing.T) {
270249
271250 // Configure the codec on the client to not return errors anymore and expect
272251 // the RPC to succeed.
273- ec .setDecodingErr ( nil )
252+ ec .decodingErr = nil
274253 if _ , err := client .EmptyCall (ctx , & testpb.Empty {}, grpc .ForceCodec (ec )); err != nil {
275254 t .Fatalf ("RPC failed with error: %v" , err )
276255 }
@@ -346,6 +325,7 @@ func (r *renameProtoCodec) Name() string { return r.name }
346325
347326// TestForceCodecName confirms that the ForceCodec call option sets the subtype
348327// in the content-type header according to the Name() of the codec provided.
328+ // Verifies that the name is converted to lowercase before transmitting.
349329func (s ) TestForceCodecName (t * testing.T ) {
350330 wantContentTypeCh := make (chan []string , 1 )
351331 defer close (wantContentTypeCh )
0 commit comments