feat(billing): 完成异步结算与请求执行闭环
统一任务成功、Attempt 与结算 Outbox 的事务边界,增加多实例安全结算、人工复核、请求幂等与执行租约。钱包决策使用九位精确金额,并通过审计保护约束保留流水事实;同时补充管理接口、指标与 PostgreSQL 集成测试。
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package runner
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/easyai/easyai-ai-gateway/apps/api/internal/store"
|
||||
)
|
||||
|
||||
func TestBillingSettlementRetryDelay(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
attempt int
|
||||
want time.Duration
|
||||
}{
|
||||
{attempt: 1, want: time.Second},
|
||||
{attempt: 2, want: 2 * time.Second},
|
||||
{attempt: 10, want: 512 * time.Second},
|
||||
{attempt: 11, want: 15 * time.Minute},
|
||||
{attempt: 20, want: 15 * time.Minute},
|
||||
}
|
||||
for _, test := range tests {
|
||||
if got := billingSettlementRetryDelay(test.attempt); got != test.want {
|
||||
t.Fatalf("attempt %d: got %s, want %s", test.attempt, got, test.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBillingSettlementErrorCode(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if got := billingSettlementErrorCode(store.ErrInsufficientWalletBalance); got != "insufficient_balance" {
|
||||
t.Fatalf("got %q", got)
|
||||
}
|
||||
if got := billingSettlementErrorCode(errors.New("boom")); got != "settlement_failed" {
|
||||
t.Fatalf("got %q", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user