fix: restore active channels after gateway restart

This commit is contained in:
hectorzhao
2026-07-15 18:30:02 +08:00
parent 7091a8bed4
commit 85ff037647
7 changed files with 61 additions and 11 deletions
+20
View File
@@ -286,6 +286,26 @@ describe('ChannelsService', () => {
expect(prisma.smsChannel.create).not.toHaveBeenCalled();
});
it('replays every active channel connection after Gateway restart', async () => {
const prisma = createPrismaMock();
const activeChannel = await prisma.smsChannel.findUnique();
prisma.smsChannel.findMany.mockResolvedValue([activeChannel]);
const service = new ChannelsService(prisma as never);
await (service as unknown as { reconnectActiveChannelsAfterGatewayRestart(): Promise<void> })
.reconnectActiveChannelsAfterGatewayRestart();
expect(prisma.smsChannel.findMany).toHaveBeenCalledWith({ where: { status: 'active' } });
expect(mockQueueAdd).toHaveBeenCalledWith('connect-channel', expect.objectContaining({
channelId: 'channel-1',
reason: 'gateway_restarted',
channel: expect.objectContaining({ rateLimitPerSecond: 100 }),
}), { jobId: 'channel-1:primary:connect' });
expect(mockFetch).toHaveBeenCalledWith('http://127.0.0.1:8090/connections/connect', expect.objectContaining({
body: expect.stringContaining('"reason":"gateway_restarted"'),
}));
});
it('creates CMPP channels and route rules with first-version defaults', async () => {
const prisma = createPrismaMock();
const service = new ChannelsService(prisma as never);