MCPcopy
hub / github.com/labstack/echo / TestRateLimiterMemoryStore_RaceDetection

Function TestRateLimiterMemoryStore_RaceDetection

middleware/rate_limiter_test.go:584–612  ·  view source on GitHub ↗

TestRateLimiterMemoryStore_RaceDetection verifies no data races with high concurrency Run with: go test -race ./middleware -run TestRateLimiterMemoryStore_RaceDetection

(t *testing.T)

Source from the content-addressed store, hash-verified

582// TestRateLimiterMemoryStore_RaceDetection verifies no data races with high concurrency
583// Run with: go test -race ./middleware -run TestRateLimiterMemoryStore_RaceDetection
584func TestRateLimiterMemoryStore_RaceDetection(t *testing.T) {
585 t.Parallel()
586
587 store := NewRateLimiterMemoryStoreWithConfig(RateLimiterMemoryStoreConfig{
588 Rate: 100,
589 Burst: 200,
590 ExpiresIn: 1 * time.Second,
591 })
592
593 const goroutines = 100
594 const requestsPerGoroutine = 100
595
596 var wg sync.WaitGroup
597 identifiers := []string{"user1", "user2", "user3", "user4", "user5"}
598
599 for i := range goroutines {
600 wg.Add(1)
601 go func(routineID int) {
602 defer wg.Done()
603 for range requestsPerGoroutine {
604 identifier := identifiers[routineID%len(identifiers)]
605 _, err := store.Allow(identifier)
606 assert.NoError(t, err)
607 }
608 }(i)
609 }
610
611 wg.Wait()
612}
613
614// TestRateLimiterMemoryStore_TimeOrdering verifies time ordering consistency in rate limiting decisions
615func TestRateLimiterMemoryStore_TimeOrdering(t *testing.T) {

Callers

nothing calls this directly

Calls 3

AddMethod · 0.65
AllowMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…