fix: 完成消息 Outbox 投递与会话状态保护
This commit is contained in:
@@ -39,6 +39,42 @@ describe("moderation worker with real PostgreSQL", () => {
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
["PENDING", null, 0],
|
||||
["PROCESSING", new Date(Date.now() - 60_000), 5],
|
||||
] as const)(
|
||||
"leaves %s MESSAGE_CREATED for the API relay",
|
||||
async (status, lockedAt, attempts) => {
|
||||
await prisma.account.create({
|
||||
data: {
|
||||
phoneCiphertext: Buffer.from("cipher"),
|
||||
phoneHmac: randomUUID(),
|
||||
},
|
||||
});
|
||||
const event = await prisma.outboxEvent.create({
|
||||
data: {
|
||||
aggregateType: "MESSAGE",
|
||||
aggregateId: randomUUID(),
|
||||
eventType: "MESSAGE_CREATED",
|
||||
dedupeKey: randomUUID(),
|
||||
payload: {
|
||||
messageId: randomUUID(),
|
||||
conversationId: randomUUID(),
|
||||
},
|
||||
status,
|
||||
lockedAt,
|
||||
lockToken: lockedAt ? randomUUID() : null,
|
||||
attempts,
|
||||
},
|
||||
});
|
||||
|
||||
expect(await new ModerationWorker(prisma).runOnce()).toBe(false);
|
||||
expect(
|
||||
await prisma.outboxEvent.findUniqueOrThrow({ where: { id: event.id } }),
|
||||
).toMatchObject({ status, attempts, lockedAt });
|
||||
},
|
||||
);
|
||||
|
||||
it("is fail-closed and exponentially reschedules failures", async () => {
|
||||
const { bottle, event } = await fixture("ordinary");
|
||||
const worker = new ModerationWorker(prisma, () => {
|
||||
|
||||
Reference in New Issue
Block a user