perf: coalesce batch progress refreshes
This commit is contained in:
@@ -924,6 +924,28 @@ describe('SendChainService', () => {
|
||||
}));
|
||||
});
|
||||
|
||||
it('coalesces concurrent batch progress refreshes and keeps a trailing refresh', async () => {
|
||||
const { service, prisma } = createService();
|
||||
let resolveFirst: ((value: Array<{ status: string; _count: { _all: number } }>) => void) | undefined;
|
||||
prisma.smsMessageRecord.groupBy
|
||||
.mockImplementationOnce(() => new Promise((resolve) => { resolveFirst = resolve; }))
|
||||
.mockResolvedValue([{ status: 'delivered', _count: { _all: 2 } }]);
|
||||
|
||||
const first = service['submission'].refreshTaskProgress('task-1');
|
||||
await Promise.resolve();
|
||||
const second = service['submission'].refreshTaskProgress('task-1');
|
||||
|
||||
expect(prisma.smsMessageRecord.groupBy).toHaveBeenCalledTimes(1);
|
||||
resolveFirst?.([{ status: 'delivered', _count: { _all: 1 } }]);
|
||||
await Promise.all([first, second]);
|
||||
|
||||
expect(prisma.smsMessageRecord.groupBy).toHaveBeenCalledTimes(2);
|
||||
expect(prisma.smsBatchTask.update).toHaveBeenLastCalledWith({
|
||||
where: { id: 'task-1' },
|
||||
data: expect.objectContaining({ progressTotal: 2, successTotal: 2, status: 'finished' }),
|
||||
});
|
||||
});
|
||||
|
||||
it('does not expose CMPP internal tasks through client task detail or messages', async () => {
|
||||
const { service, prisma } = createService();
|
||||
prisma.smsBatchTask.findFirst.mockResolvedValue(null);
|
||||
|
||||
Reference in New Issue
Block a user