文件
shanghaipeiwan/server/tests/order-timeout-scheduler.spec.ts
xcbyy d665cd6976 feat(order): 订单超时自动流转改为后台定时任务
- 新增 startOrderTimeoutScheduler:默认每 60s 扫描(ORDER_TIMEOUT_SCAN_MS 可配,DISABLE_ORDER_TIMEOUT_SCAN=1 可禁用),带防重入与 unref

- 启动时自动开启;移除订单查询接口里的被动扫描,避免每次请求触发

- 文档补充定时扫描环境变量;新增回归护栏 order-timeout-scheduler.spec.ts(83 套件/622 用例全绿)
2026-10-19 09:22:52 +08:00

32 行
1.3 KiB
TypeScript

// 已读取AGENTS.md
import * as fs from 'fs';
import * as path from 'path';
/**
* 第六十七批回归闸门:订单超时自动流转改为后台定时任务
*/
describe('第六十七批订单超时定时任务闸门', () => {
const rootDir = path.resolve(__dirname, '../../');
const indexCode = fs.readFileSync(path.join(rootDir, 'server/src/index.ts'), 'utf-8');
const repoCode = fs.readFileSync(path.join(rootDir, 'server/src/db/repository.ts'), 'utf-8');
it('提供可配置的订单超时扫描定时任务', () => {
expect(indexCode).toContain('function startOrderTimeoutScheduler(');
expect(indexCode).toContain('ORDER_TIMEOUT_SCAN_MS');
expect(indexCode).toContain('DISABLE_ORDER_TIMEOUT_SCAN');
expect(indexCode).toContain('setInterval(');
expect(indexCode).toContain('orderTimeoutRunning');
});
it('启动时启用定时任务', () => {
const bootstrapStart = indexCode.indexOf('async function bootstrap(');
expect(bootstrapStart).toBeGreaterThan(-1);
const block = indexCode.slice(bootstrapStart, bootstrapStart + 1200);
expect(block).toContain('startOrderTimeoutScheduler();');
});
it('订单查询不再按请求被动触发超时扫描(改由定时任务统一处理)', () => {
expect(repoCode).not.toContain('await this.processOrderTimeouts().catch');
});
});