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

Method TestManager_Enabled_ActiveSinceLastCheck

internal/idle/idle_test.go:203–250  ·  view source on GitHub ↗

TestManager_Enabled_ActiveSinceLastCheck tests the case where the idle manager is enabled. Ensures that when there are active RPCs in the last period (even though there is no active call when the timer fires), the channel does not enter idle mode.

(t *testing.T)

Source from the content-addressed store, hash-verified

201// period (even though there is no active call when the timer fires), the
202// channel does not enter idle mode.
203func (s) TestManager_Enabled_ActiveSinceLastCheck(t *testing.T) {
204 callbackCh := overrideNewTimer(t)
205
206 enforcer := newTestEnforcer()
207 mgr := NewManager(enforcer, time.Duration(defaultTestIdleTimeout))
208 defer mgr.Close()
209 mgr.ExitIdleMode()
210
211 // Fire up a goroutine that simulates unary RPCs until the timer callback
212 // fires.
213 timerFired := make(chan struct{})
214 go func() {
215 for ; ; <-time.After(defaultTestShortTimeout) {
216 mgr.OnCallBegin()
217 mgr.OnCallEnd()
218
219 select {
220 case <-timerFired:
221 return
222 default:
223 }
224 }
225 }()
226
227 // Ensure that the timer callback fires, and that we don't enter idle as
228 // part of this invocation of the timer callback, since we had some RPCs in
229 // this period.
230 select {
231 case <-callbackCh:
232 close(timerFired)
233 case <-time.After(2 * defaultTestIdleTimeout):
234 close(timerFired)
235 t.Fatal("Timeout waiting for idle timer callback to fire")
236 }
237 select {
238 case <-enforcer.enterIdleCh:
239 t.Fatalf("EnterIdleMode() called on enforcer when one RPC completed in the last period")
240 case <-time.After(defaultTestShortTimeout):
241 }
242
243 // Since the unary RPC terminated and we have no other active RPCs, the
244 // channel must move to idle eventually.
245 select {
246 case <-enforcer.enterIdleCh:
247 case <-time.After(defaultTestTimeout):
248 t.Fatal("Timeout waiting for channel to move to idle")
249 }
250}
251
252// TestManager_Enabled_ExitIdleOnRPC tests the case where the idle
253// manager is enabled. Ensures that the channel moves out of idle when an RPC is

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
FatalfMethod · 0.65

Tested by

no test coverage detected