TestTryFastFailOpen_DownProbeOnePerInterval is the core load-shedding test. It asserts that across N concurrent callers while connectorDown is latched, exactly ONE is elected as the probe (returns nil → real DB path) per probe interval; everyone else gets the fast-path emergency user. This is what b
(t *testing.T)
| 311 | // user. This is what bounds per-request DB load during a sustained |
| 312 | // outage to ~1 query/sec instead of full request rate. |
| 313 | func TestTryFastFailOpen_DownProbeOnePerInterval(t *testing.T) { |
| 314 | t.Parallel() |
| 315 | fc := &fakeConnector{id: "test"} |
| 316 | s := newTestStrategyWith(t, fc, true) |
| 317 | |
| 318 | // Latch down and force the timestamp far in the past so every caller |
| 319 | // sees the probe window as expired. |
| 320 | s.markConnectorDown() |
| 321 | s.connectorDownSince.Store(time.Now().Add(-1 * time.Hour).UnixNano()) |
| 322 | |
| 323 | var probes atomic.Int64 |
| 324 | var fastPathed atomic.Int64 |
| 325 | |
| 326 | const concurrency = 200 |
| 327 | var wg sync.WaitGroup |
| 328 | start := make(chan struct{}) |
| 329 | for i := 0; i < concurrency; i++ { |
| 330 | wg.Add(1) |
| 331 | go func() { |
| 332 | defer wg.Done() |
| 333 | <-start |
| 334 | if u := s.tryFastFailOpen(); u != nil { |
| 335 | fastPathed.Add(1) |
| 336 | } else { |
| 337 | probes.Add(1) |
| 338 | } |
| 339 | }() |
| 340 | } |
| 341 | close(start) |
| 342 | wg.Wait() |
| 343 | |
| 344 | assert.Equal(t, int64(1), probes.Load(), |
| 345 | "exactly one caller must be elected as the probe per interval; got %d", probes.Load()) |
| 346 | assert.Equal(t, int64(concurrency-1), fastPathed.Load(), |
| 347 | "all other callers must fast-path; got %d", fastPathed.Load()) |
| 348 | } |
| 349 | |
| 350 | // TestTryFastFailOpen_DownWithinWindow verifies that during the cooldown |
| 351 | // window (downSince fresh), ALL callers fast-path — no probes are elected |
nothing calls this directly
no test coverage detected