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

Method TestManager_Enabled_ExitIdleOnRPC

internal/idle/idle_test.go:255–294  ·  view source on GitHub ↗

TestManager_Enabled_ExitIdleOnRPC tests the case where the idle manager is enabled. Ensures that the channel moves out of idle when an RPC is initiated.

(t *testing.T)

Source from the content-addressed store, hash-verified

253// manager is enabled. Ensures that the channel moves out of idle when an RPC is
254// initiated.
255func (s) TestManager_Enabled_ExitIdleOnRPC(t *testing.T) {
256 overrideNewTimer(t)
257
258 enforcer := newTestEnforcer()
259 mgr := NewManager(enforcer, time.Duration(defaultTestIdleTimeout))
260 defer mgr.Close()
261
262 mgr.ExitIdleMode()
263 <-enforcer.exitIdleCh
264 // Ensure that the channel moves to idle since there are no RPCs.
265 select {
266 case <-enforcer.enterIdleCh:
267 case <-time.After(2 * defaultTestIdleTimeout):
268 t.Fatal("Timeout waiting for channel to move to idle mode")
269 }
270
271 for i := 0; i < 100; i++ {
272 // A call to OnCallBegin and OnCallEnd simulates an RPC.
273 go func() {
274 mgr.OnCallBegin()
275 mgr.OnCallEnd()
276 }()
277 }
278
279 // Ensure that the channel moves out of idle as a result of the above RPC.
280 select {
281 case <-enforcer.exitIdleCh:
282 case <-time.After(2 * defaultTestIdleTimeout):
283 t.Fatal("Timeout waiting for channel to move out of idle mode")
284 }
285
286 // Ensure that only one call to exit idle mode is made to the CC.
287 sCtx, sCancel := context.WithTimeout(context.Background(), defaultTestShortTimeout)
288 defer sCancel()
289 select {
290 case <-enforcer.exitIdleCh:
291 t.Fatal("More than one call to exit idle mode on the ClientConn; only one expected")
292 case <-sCtx.Done():
293 }
294}
295
296type racyState int32
297

Callers

nothing calls this directly

Calls 9

CloseMethod · 0.95
ExitIdleModeMethod · 0.95
OnCallBeginMethod · 0.95
OnCallEndMethod · 0.95
overrideNewTimerFunction · 0.85
newTestEnforcerFunction · 0.85
NewManagerFunction · 0.85
FatalMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected