fix: 限定捞瓶查询与重试成本
This commit is contained in:
@@ -285,7 +285,9 @@ describe("match API with real PostgreSQL", () => {
|
||||
const results = await Promise.all(
|
||||
Array.from({ length: 8 }, () => pick(picker.authorization, key)),
|
||||
);
|
||||
expect(results.every((x) => x.status === 201)).toBe(true);
|
||||
expect(results.map((x) => [x.status, x.body.code])).toEqual(
|
||||
Array.from({ length: 8 }, () => [201, "OK"]),
|
||||
);
|
||||
expect(new Set(results.map((x) => x.body.data.lease.id))).toHaveLength(1);
|
||||
expect(new Set(results.map((x) => x.body.data.lease.token))).toHaveLength(
|
||||
1,
|
||||
@@ -451,6 +453,56 @@ describe("match API with real PostgreSQL", () => {
|
||||
await pick(picker.authorization).expect(201);
|
||||
}, 15_000);
|
||||
|
||||
it("sustains twenty rounds of 21 concurrent distinct requests without picker-level serialization", async () => {
|
||||
for (let round = 0; round < 20; round += 1) {
|
||||
await prisma.$executeRawUnsafe(`TRUNCATE TABLE "accounts" CASCADE`);
|
||||
const author = await actor(`stress-author-${round}`);
|
||||
const picker = await actor(`stress-picker-${round}`);
|
||||
await prisma.bottle.createMany({
|
||||
data: Array.from({ length: 96 }, (_, index) => ({
|
||||
authorId: author.id,
|
||||
clientRequestId: `stress-${round}-${index}`,
|
||||
contentText: `stress-${round}-${index}`,
|
||||
reviewStatus: "APPROVED" as const,
|
||||
poolStatus: "IN_POOL" as const,
|
||||
approvedAt: new Date(),
|
||||
})),
|
||||
});
|
||||
|
||||
const results = await Promise.all(
|
||||
Array.from({ length: 21 }, (_, index) =>
|
||||
pick(picker.authorization, `stress-key-${round}-${index}`),
|
||||
),
|
||||
);
|
||||
expect(results.filter(({ status }) => status === 201)).toHaveLength(20);
|
||||
expect(
|
||||
results.filter(
|
||||
({ status, body }) =>
|
||||
status === 429 && body.code === "BOTTLE_DAILY_LIMIT",
|
||||
),
|
||||
).toHaveLength(1);
|
||||
expect(results.filter(({ status }) => status >= 500)).toHaveLength(0);
|
||||
expect(
|
||||
await prisma.dailyUsage.findFirstOrThrow({
|
||||
where: { accountId: picker.id },
|
||||
}),
|
||||
).toMatchObject({ bottlesPicked: 20 });
|
||||
expect(
|
||||
await prisma.bottlePickLease.count({ where: { pickerId: picker.id } }),
|
||||
).toBe(20);
|
||||
expect(
|
||||
await prisma.bottlePickHistory.count({
|
||||
where: { pickerId: picker.id },
|
||||
}),
|
||||
).toBe(20);
|
||||
expect(
|
||||
await prisma.bottlePickRequest.count({
|
||||
where: { pickerId: picker.id },
|
||||
}),
|
||||
).toBe(20);
|
||||
}
|
||||
}, 120_000);
|
||||
|
||||
it.each(["SUSPENSION", "BAN"] as const)(
|
||||
"rejects active %s sanction",
|
||||
async (type) => {
|
||||
|
||||
Reference in New Issue
Block a user