TestRateLimiterMemoryStore_RaceDetection verifies no data races with high concurrency Run with: go test -race ./middleware -run TestRateLimiterMemoryStore_RaceDetection
(t *testing.T)
| 582 | // TestRateLimiterMemoryStore_RaceDetection verifies no data races with high concurrency |
| 583 | // Run with: go test -race ./middleware -run TestRateLimiterMemoryStore_RaceDetection |
| 584 | func 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 |
| 615 | func TestRateLimiterMemoryStore_TimeOrdering(t *testing.T) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…