perf(cmpp): instrument inbound flow and unbatch submit worker

This commit is contained in:
hectorzhao
2026-08-20 11:27:35 +08:00
parent c4f36fc50d
commit b9a71fe0b9
23 changed files with 760 additions and 138 deletions
@@ -11,7 +11,17 @@ describe('GatewayEventsController protocol logging', () => {
const protocolLogs = {
record: jest.fn(),
};
const controller = new GatewayEventsController(sendChain as never, {} as never, protocolLogs as never, { recordEvent: jest.fn() } as never);
const metrics = {
beginCmppInboundStage: jest.fn().mockReturnValue(1n),
finishCmppInboundStage: jest.fn(),
};
const controller = new GatewayEventsController(
sendChain as never,
{} as never,
protocolLogs as never,
{ recordEvent: jest.fn() } as never,
metrics as never,
);
beforeEach(() => {
jest.clearAllMocks();
@@ -77,6 +87,20 @@ describe('GatewayEventsController protocol logging', () => {
}));
});
it('records a failed inbound total without swallowing the service error', async () => {
const failure = new Error('inbound failed');
(sendChain as Record<string, jest.Mock>).submitInboundMessage = jest.fn().mockRejectedValue(failure);
await expect(controller.submitInbound({
account: '607532',
phoneNumber: '13127620092',
content: 'failed',
sequenceId: 142,
})).rejects.toBe(failure);
expect(metrics.finishCmppInboundStage).toHaveBeenCalledWith(1n, 'total', 'error');
});
it('accepts only safe outbound Gateway packet events', () => {
expect(controller.protocolLog({
protocol: 'cmpp',
@@ -155,6 +179,7 @@ describe('GatewayEventsController protocol logging', () => {
messageId: 'MSG-1',
status: 'success',
}));
expect(metrics.finishCmppInboundStage).toHaveBeenCalledWith(1n, 'total', 'success');
});
it('replaces a fallback receipt identifier with the resolved main message identifier', async () => {