WMS_MAIN/test/app/service/systems/qimen_query.test.js
liufumingren cf3b9092c6 fix(qimen): 出站请求日志使用独立 log_id 并幂等消费日志队列
- qimen_client.sendRequest 出站日志改为 generateLogId() 生成 QL-<时间戳>-<随机>,
  不再复用入站 ctx.qimenLogId,避免与入站文件队列落库撞 wms_qimen_log.log_id 唯一索引
- qimen.saveQimenLog 去掉 ctx.qimenLogId 兜底;saveQimenLogResult / saveQimenLogBody
  改为按 log_id 定位更新(原先按 id 字段更新与调用语义不符)
- schedule/consume_qimen_logs 插入遇 ER_DUP_ENTRY 视为幂等命中跳过并推进消费进度,
  避免重复日志卡死文件队列
- test: qimen_query.test.js 断言改为校验新 log_id 格式
2026-09-13 15:29:43 +08:00

61 lines
1.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
const assert = require('node:assert/strict');
const http = require('node:http');
const QimenQueryService = require('../../../../app/service/systems/qimen_query');
describe('test/app/service/systems/qimen_query.test.js', () => {
it('should save qimen log with error info when http.request throws', async () => {
const originalRequest = http.request;
let savedLog = null;
const ctx = {
qimenLogId: 'QL-20260414-abc123',
app: {},
logger: {
info() {},
warn() {},
error() {},
debug() {},
},
service: {
qimen: {
async saveQimenLog(logData) {
savedLog = { ...logData };
return 123;
},
},
},
};
const service = new QimenQueryService(ctx);
http.request = () => {
throw new Error('network down');
};
try {
await assert.rejects(
async () => await service.sendRequest('http://example.com/router', '<request/>', {
body: '<request/>',
from_key: 'from-key',
to_key: 'to-key',
method: 'demo.method',
sign: 'demo-sign',
costomer_id: 'customer-1',
v: '2.0',
url: 'http://example.com/router',
}),
/network down/
);
} finally {
http.request = originalRequest;
}
assert.ok(savedLog);
// 出站日志不复用入站 ctx.qimenLogId,使用独立生成的 log_id,避免唯一索引冲突
assert.match(savedLog.log_id, /^QL-\d{13}-[0-9a-f]{6}$/);
assert.equal(savedLog.body, '<request/>');
assert.match(savedLog.result, /network down/);
});
});