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

Method TestChannelIdleness_Enabled_OngoingCall

internal/idle/idle_e2e_test.go:225–339  ·  view source on GitHub ↗

Tests the case where channel idleness is enabled by passing a small value for idle_timeout. Verifies that a READY channel with an ongoing RPC stays READY.

(t *testing.T)

Source from the content-addressed store, hash-verified

223// Tests the case where channel idleness is enabled by passing a small value for
224// idle_timeout. Verifies that a READY channel with an ongoing RPC stays READY.
225func (s) TestChannelIdleness_Enabled_OngoingCall(t *testing.T) {
226 tests := []struct {
227 name string
228 makeRPC func(ctx context.Context, client testgrpc.TestServiceClient) error
229 }{
230 {
231 name: "unary",
232 makeRPC: func(ctx context.Context, client testgrpc.TestServiceClient) error {
233 if _, err := client.EmptyCall(ctx, &testpb.Empty{}); err != nil {
234 return fmt.Errorf("EmptyCall RPC failed: %v", err)
235 }
236 return nil
237 },
238 },
239 {
240 name: "streaming",
241 makeRPC: func(ctx context.Context, client testgrpc.TestServiceClient) error {
242 stream, err := client.FullDuplexCall(ctx)
243 if err != nil {
244 t.Fatalf("FullDuplexCall RPC failed: %v", err)
245 }
246 if _, err := stream.Recv(); err != nil && err != io.EOF {
247 t.Fatalf("stream.Recv() failed: %v", err)
248 }
249 return nil
250 },
251 },
252 }
253
254 for _, test := range tests {
255 t.Run(test.name, func(t *testing.T) {
256 closeCh := registerWrappedRoundRobinPolicy(t)
257
258 // Create a ClientConn with a short idle_timeout.
259 r := manual.NewBuilderWithScheme("whatever")
260 dopts := []grpc.DialOption{
261 grpc.WithTransportCredentials(insecure.NewCredentials()),
262 grpc.WithResolvers(r),
263 grpc.WithIdleTimeout(defaultTestShortIdleTimeout),
264 grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"round_robin":{}}]}`),
265 }
266 cc, err := grpc.NewClient(r.Scheme()+":///test.server", dopts...)
267 if err != nil {
268 t.Fatalf("grpc.NewClient() failed: %v", err)
269 }
270 defer cc.Close()
271 cc.Connect()
272 // Start a test backend that keeps the RPC call active by blocking
273 // on a channel that is closed by the test later on.
274 blockCh := make(chan struct{})
275 backend := &stubserver.StubServer{
276 EmptyCallF: func(context.Context, *testpb.Empty) (*testpb.Empty, error) {
277 <-blockCh
278 return &testpb.Empty{}, nil
279 },
280 FullDuplexCallF: func(testgrpc.TestService_FullDuplexCallServer) error {
281 <-blockCh
282 return nil

Callers

nothing calls this directly

Calls 15

StartServerMethod · 0.95
StopMethod · 0.95
NewBuilderWithSchemeFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
WithResolversFunction · 0.92
WithIdleTimeoutFunction · 0.92
WithDefaultServiceConfigFunction · 0.92
NewClientFunction · 0.92
AwaitStateFunction · 0.92
EmptyCallMethod · 0.65

Tested by

no test coverage detected