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

Method TestManager_Enabled_OngoingCall

internal/idle/idle_test.go:157–197  ·  view source on GitHub ↗

TestManager_Enabled_OngoingCall tests the case where the idle manager is enabled. Ensures that when there is an ongoing RPC, the channel does not enter idle mode.

(t *testing.T)

Source from the content-addressed store, hash-verified

155// is enabled. Ensures that when there is an ongoing RPC, the channel does not
156// enter idle mode.
157func (s) TestManager_Enabled_OngoingCall(t *testing.T) {
158 callbackCh := overrideNewTimer(t)
159
160 enforcer := newTestEnforcer()
161 mgr := NewManager(enforcer, time.Duration(defaultTestIdleTimeout))
162 defer mgr.Close()
163 mgr.ExitIdleMode()
164
165 // Fire up a goroutine that simulates an ongoing RPC that is terminated
166 // after the timer callback fires for the first time.
167 timerFired := make(chan struct{})
168 go func() {
169 mgr.OnCallBegin()
170 <-timerFired
171 mgr.OnCallEnd()
172 }()
173
174 // Ensure that the timer callback fires and unblock the above goroutine.
175 select {
176 case <-callbackCh:
177 close(timerFired)
178 case <-time.After(2 * defaultTestIdleTimeout):
179 t.Fatal("Timeout waiting for idle timer callback to fire")
180 }
181
182 // The invocation of the timer callback should not put the channel in idle
183 // mode since we had an ongoing RPC.
184 select {
185 case <-enforcer.enterIdleCh:
186 t.Fatalf("EnterIdleMode() called on enforcer when active RPC exists")
187 case <-time.After(defaultTestShortTimeout):
188 }
189
190 // Since we terminated the ongoing RPC and we have no other active RPCs, the
191 // channel must move to idle eventually.
192 select {
193 case <-enforcer.enterIdleCh:
194 case <-time.After(defaultTestTimeout):
195 t.Fatal("Timeout waiting for channel to move to idle")
196 }
197}
198
199// TestManager_Enabled_ActiveSinceLastCheck tests the case where the
200// idle manager is enabled. Ensures that when there are active RPCs in the last

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