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)
| 155 | // is enabled. Ensures that when there is an ongoing RPC, the channel does not |
| 156 | // enter idle mode. |
| 157 | func (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 |
nothing calls this directly
no test coverage detected