mirror of
https://github.com/karust/openserp.git
synced 2026-08-12 11:53:29 +08:00
- 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
39 lines
892 B
Go
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)
|
|
}
|
|
}
|