Files
go-admin/config/extend_test.go
T
zhangwenjian cd8edfa5d4 fix🐛: reject rate-limited requests with 429 and make the threshold configurable
A rejected request answered 200 with the failure only in the body, so every
layer that reads the status line counted it as served: load balancers, metrics,
client-side retry. A load test against this reported the limiter's own
rejections as successful traffic and overstated throughput more than tenfold.

The threshold was a constant in the middleware, which made 200 QPS the ceiling
of every deployment with nothing in the configuration to reveal it. It now
reads extend.rateLimit.inboundQPS; an absent value keeps 200, so an upgrade
changes nothing, and zero disables the limiter for a deployment behind its own
gateway.

Also drops Strategy: system.BBR. Reading sentinel's source, the adaptive
strategy is consulted only for Load and CpuUsage - for InboundQPS the trigger
count is compared directly - so it read as if the limit adapted to the machine
when it never did.
2026-08-28 19:42:21 +08:00

35 lines
1.1 KiB
Go

package config
import "testing"
func TestObjectStoreConfigured(t *testing.T) {
if (ObjectStore{}).Configured() {
t.Fatal("empty store reported as configured")
}
full := ObjectStore{Endpoint: "e", AccessKeyID: "a", AccessKeySecret: "s", BucketName: "b"}
if !full.Configured() {
t.Fatal("complete store reported as unconfigured")
}
if (ObjectStore{Endpoint: "e", AccessKeyID: "a"}).Configured() {
t.Fatal("partial store reported as configured")
}
}
func TestRateLimitThreshold(t *testing.T) {
// Absent is the case an existing settings.yml hits after an upgrade: it has
// no ratelimit section, and must keep the limit it always had.
if got := (RateLimit{}).Threshold(); got != DefaultInboundQPS {
t.Errorf("unconfigured limit = %v, want the default %v", got, DefaultInboundQPS)
}
zero := 0.0
if got := (RateLimit{InboundQPS: &zero}).Threshold(); got != 0 {
t.Errorf("explicit zero = %v, want 0 so the limiter can be turned off", got)
}
custom := 1500.0
if got := (RateLimit{InboundQPS: &custom}).Threshold(); got != custom {
t.Errorf("configured limit = %v, want %v", got, custom)
}
}