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)
| 253 | // manager is enabled. Ensures that the channel moves out of idle when an RPC is |
| 254 | // initiated. |
| 255 | func (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 | |
| 296 | type racyState int32 |
| 297 |
nothing calls this directly
no test coverage detected