Files
openserp/core/rate_limiter_test.go
Rustem Kamalov 04db5347a8 fix(core): harden extract and stabilize request protection
- breaker: stop counting client cancellations/deadlines (incl. bare
  rate-limiter wait errors) and circuit-open as engine failures
- rate limiting: cache limiters in SearchEngineOptions and rawEngine so
  pacing applies on raw/library paths; pool wrapper delegates
- /extract SSRF guard: public-IP-only policy with dial-time IP pinning,
  redirect re-validation, rendered-mode preflight, http/https allow-list,
  ErrTargetNotAllowed -> HTTP 400, extract.allow_private_networks
  escape hatch (default off)
- browser: no rod Must* on the request path; CLI parses block_resources
  without panicking
2026-06-12 18:09:40 +03:00

39 lines
892 B
Go

package core
import (
"context"
"testing"
"time"
)
func TestSearchEngineOptionsGetRateLimiterCachesLimiterAndPaces(t *testing.T) {
opts := SearchEngineOptions{
RateRequests: 20,
RateTime: 1,
RateBurst: 1,
SelectorTimeout: 1,
}
limiter := opts.GetRateLimiter()
if limiter == nil {
t.Fatal("expected limiter")
}
if got := opts.GetRateLimiter(); got != limiter {
t.Fatal("expected GetRateLimiter to return the cached limiter")
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
if err := limiter.Wait(ctx); err != nil {
t.Fatalf("first wait failed: %v", err)
}
start := time.Now()
if err := limiter.Wait(ctx); err != nil {
t.Fatalf("second wait failed: %v", err)
}
if elapsed := time.Since(start); elapsed < 40*time.Millisecond {
t.Fatalf("second wait elapsed %s, want pacing near 50ms", elapsed)
}
}