feat(v2): reconcile Runner 骨架 + 订单级过期清理(超 TTL pending 单/零尝试孤儿单自动关闭)
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package reconcile_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/wangjia/pay/internal/model"
|
||||
"github.com/wangjia/pay/internal/reconcile"
|
||||
"github.com/wangjia/pay/internal/store"
|
||||
)
|
||||
|
||||
func TestOrderExpirerTaskClosesStalePending(t *testing.T) {
|
||||
db := model.OpenTestDB(t)
|
||||
s := store.NewOrderStore(db)
|
||||
now := time.Date(2026, 7, 10, 12, 0, 0, 0, time.UTC)
|
||||
|
||||
o := &model.OrderV2{OutTradeNo: "OLD", AmountMinor: 100, Currency: "USDT", Status: model.OrderPendingV2}
|
||||
_ = s.CreateOrder(o)
|
||||
_ = db.Model(&model.OrderV2{}).Where("out_trade_no = ?", "OLD").
|
||||
Update("created_at", now.Add(-2*time.Hour)).Error
|
||||
|
||||
task := reconcile.OrderExpirerTask(s, time.Hour, func() time.Time { return now })
|
||||
if err := task(context.Background()); err != nil {
|
||||
t.Fatalf("task: %v", err)
|
||||
}
|
||||
got, _ := s.GetOrder("OLD")
|
||||
if got.Status != model.OrderExpiredV2 {
|
||||
t.Fatalf("超时 pending 单应 expired, got %v", got.Status)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user