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

Method TestChannelIdleness_Disabled_NoActivity

internal/idle/idle_e2e_test.go:119–161  ·  view source on GitHub ↗

Tests the case where channel idleness is disabled by passing an idle_timeout of 0. Verifies that a READY channel with no RPCs does not move to IDLE.

(t *testing.T)

Source from the content-addressed store, hash-verified

117// Tests the case where channel idleness is disabled by passing an idle_timeout
118// of 0. Verifies that a READY channel with no RPCs does not move to IDLE.
119func (s) TestChannelIdleness_Disabled_NoActivity(t *testing.T) {
120 closeCh := registerWrappedRoundRobinPolicy(t)
121
122 // Create a ClientConn with idle_timeout set to 0.
123 r := manual.NewBuilderWithScheme("whatever")
124 dopts := []grpc.DialOption{
125 grpc.WithTransportCredentials(insecure.NewCredentials()),
126 grpc.WithResolvers(r),
127 grpc.WithIdleTimeout(0), // Disable idleness.
128 grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"round_robin":{}}]}`),
129 }
130 cc, err := grpc.NewClient(r.Scheme()+":///test.server", dopts...)
131 if err != nil {
132 t.Fatalf("grpc.NewClient() failed: %v", err)
133 }
134 defer cc.Close()
135 cc.Connect()
136
137 // Start a test backend and push an address update via the resolver.
138 backend := stubserver.StartTestService(t, nil)
139 defer backend.Stop()
140 r.UpdateState(resolver.State{Addresses: []resolver.Address{{Addr: backend.Address}}})
141
142 // Verify that the ClientConn moves to READY.
143 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
144 defer cancel()
145 testutils.AwaitState(ctx, t, cc, connectivity.Ready)
146
147 // Verify that the ClientConn stays in READY.
148 sCtx, sCancel := context.WithTimeout(ctx, 3*defaultTestShortIdleTimeout)
149 defer sCancel()
150 testutils.AwaitNoStateChange(sCtx, t, cc, connectivity.Ready)
151
152 // Verify that the LB policy is not closed which is expected to happen when
153 // the channel enters IDLE.
154 sCtx, sCancel = context.WithTimeout(ctx, defaultTestShortIdleTimeout)
155 defer sCancel()
156 select {
157 case <-sCtx.Done():
158 case <-closeCh:
159 t.Fatal("LB policy closed when expected not to")
160 }
161}
162
163// Tests the case where channel idleness is enabled by passing a small value for
164// idle_timeout. Verifies that a READY channel with no RPCs moves to IDLE, and

Callers

nothing calls this directly

Calls 15

NewBuilderWithSchemeFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
WithResolversFunction · 0.92
WithIdleTimeoutFunction · 0.92
WithDefaultServiceConfigFunction · 0.92
NewClientFunction · 0.92
StartTestServiceFunction · 0.92
AwaitStateFunction · 0.92
AwaitNoStateChangeFunction · 0.92
SchemeMethod · 0.65

Tested by

no test coverage detected