fix: 避免识别异常与支付锁泄漏
修复 ASR 取消后的孤立会话、OCR 表格重复及支付锁无法回收的问题,并补充回归测试。
This commit is contained in:
+27
-1
@@ -11,7 +11,7 @@ import {
|
||||
verifyMessageSignature,
|
||||
decryptAesGcm,
|
||||
} from "../utils/wechatpay.js";
|
||||
import { createOrderQueryCache, HandlerPayment } from "../handler/payment.js";
|
||||
import { createOrderQueryCache, HandlerPayment, withPayLock, payLocks } from "../handler/payment.js";
|
||||
import { DBModel } from "../models/index.js";
|
||||
|
||||
test("元转分按小数点拆位,不经过浮点", () => {
|
||||
@@ -213,3 +213,29 @@ test("退款成功后的迟到处理中结果不会回退支付与订单状态",
|
||||
Object.assign(DBModel, previous);
|
||||
}
|
||||
});
|
||||
|
||||
test("同一订单支付锁保持串行并在完成后清理", async () => {
|
||||
const key = "payment-lock-test";
|
||||
const order = [];
|
||||
let releaseFirst;
|
||||
payLocks.delete(key);
|
||||
|
||||
const first = withPayLock(key, async () => {
|
||||
order.push("first-start");
|
||||
await new Promise((resolve) => { releaseFirst = resolve; });
|
||||
order.push("first-end");
|
||||
});
|
||||
const second = withPayLock(key, async () => {
|
||||
order.push("second-start");
|
||||
order.push("second-end");
|
||||
});
|
||||
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
assert.deepEqual(order, ["first-start"]);
|
||||
assert.equal(payLocks.has(key), true);
|
||||
|
||||
releaseFirst();
|
||||
await Promise.all([first, second]);
|
||||
assert.deepEqual(order, ["first-start", "first-end", "second-start", "second-end"]);
|
||||
assert.equal(payLocks.has(key), false);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user