MCPcopy Create free account
hub / github.com/erpc/erpc / TestTryFastFailOpen_DownProbeOnePerInterval

Function TestTryFastFailOpen_DownProbeOnePerInterval

auth/strategy_database_test.go:313–348  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

311// user. This is what bounds per-request DB load during a sustained
312// outage to ~1 query/sec instead of full request rate.
313func 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

Callers

nothing calls this directly

Calls 7

newTestStrategyWithFunction · 0.85
markConnectorDownMethod · 0.80
StoreMethod · 0.80
tryFastFailOpenMethod · 0.80
WaitMethod · 0.80
LoadMethod · 0.80
AddMethod · 0.65

Tested by

no test coverage detected