MCPcopy
hub / github.com/grpc/grpc-go / testStreamSetSendCompressorSuccess

Function testStreamSetSendCompressorSuccess

encoding/compressor_test.go:139–181  ·  encoding/compressor_test.go::testStreamSetSendCompressorSuccess
(t *testing.T, payload *testpb.Payload, resCompressor string, wantCompressInvokes int32, dialOpts []grpc.DialOption)

Source from the content-addressed store, hash-verified

137}
138
139func testStreamSetSendCompressorSuccess(t *testing.T, payload *testpb.Payload, resCompressor string, wantCompressInvokes int32, dialOpts []grpc.DialOption) {
140 wc := setupGzipWrapCompressor(t)
141 ss := &stubserver.StubServer{
142 FullDuplexCallF: func(stream testgrpc.TestService_FullDuplexCallServer) error {
143 if _, err := stream.Recv(); err != nil {
144 return err
145 }
146
147 if err := grpc.SetSendCompressor(stream.Context(), resCompressor); err != nil {
148 return err
149 }
150
151 return stream.Send(&testpb.StreamingOutputCallResponse{
152 Payload: payload,
153 })
154 },
155 }
156 if err := ss.Start(nil, dialOpts...); err != nil {
157 t.Fatalf("Error starting endpoint server: %v", err)
158 }
159 defer ss.Stop()
160
161 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
162 defer cancel()
163
164 s, err := ss.Client.FullDuplexCall(ctx)
165 if err != nil {
166 t.Fatalf("Unexpected full duplex call error, got: %v, want: nil", err)
167 }
168
169 if err := s.Send(&testpb.StreamingOutputCallRequest{}); err != nil {
170 t.Fatalf("Unexpected full duplex call send error, got: %v, want: nil", err)
171 }
172
173 if _, err := s.Recv(); err != nil {
174 t.Fatalf("Unexpected full duplex recv error, got: %v, want: nil", err)
175 }
176
177 compressInvokes := atomic.LoadInt32(&wc.compressInvokes)
178 if compressInvokes != wantCompressInvokes {
179 t.Fatalf("Unexpected compress invokes, got:%d, want: %d", compressInvokes, wantCompressInvokes)
180 }
181}
182
183// fakeCompressor returns a messages of a configured size, irrespective of the
184// input.

Callers 1

Calls 9

StartMethod · 0.95
StopMethod · 0.95
SetSendCompressorFunction · 0.92
setupGzipWrapCompressorFunction · 0.85
RecvMethod · 0.65
ContextMethod · 0.65
SendMethod · 0.65
FatalfMethod · 0.65
FullDuplexCallMethod · 0.65

Tested by

no test coverage detected