refactor(*): 平台架构 - 拆分后端领域模块并同步插件协议与模型能力
This commit is contained in:
26
backend/internal/app/registration_limits_test.go
Normal file
26
backend/internal/app/registration_limits_test.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"infinite-canvas/backend/internal/platform"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestRequestRetryAfterMatchesWindow(t *testing.T) {
|
||||
s := &Service{coordinator: platform.NewCoordinatorWithRedis(nil, "registration-test")}
|
||||
ctx := context.Background()
|
||||
if ok, err := s.AllowRequest(ctx, "email-code:test", 1, time.Hour); err != nil || !ok {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if ok, _ := s.AllowRequest(ctx, "email-code:test", 1, time.Hour); ok {
|
||||
t.Fatal("limit bypassed")
|
||||
}
|
||||
wait := s.RequestRetryAfter(ctx, "email-code:test", time.Hour)
|
||||
if wait < 59*time.Minute || wait > time.Hour {
|
||||
t.Fatalf("wrong wait: %v", wait)
|
||||
}
|
||||
if s.coordinator.LocalRateCount() != 1 {
|
||||
t.Fatal("rejection consumed quota")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user