feat: 简化通道组顺序调整并过滤不可选通道
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import { selectChannelCandidate } from './send-chain.helpers';
|
||||
|
||||
const connected = [{ status: 'connected', currentConnections: 1, desiredConnections: 1 }];
|
||||
const member = (channelId: string, priority: number, isBackup = false) => ({
|
||||
channelId,
|
||||
priority,
|
||||
isBackup,
|
||||
weight: isBackup ? 1 : 100,
|
||||
carrier: 'mobile',
|
||||
province: null,
|
||||
channel: { carrier: 'mobile', sendRegion: '全国', status: 'active', connectionStates: connected },
|
||||
});
|
||||
|
||||
describe('channel group displayed order and retry selection', () => {
|
||||
it.each([
|
||||
[member('last', 30), member('first', 10, true), member('middle', 20)],
|
||||
[member('last', 3), member('first', 1, true), member('middle', 2)],
|
||||
[member('last', 2147483647), member('first', -10, true), member('middle', 0)],
|
||||
])('consumes ascending slots even when backup flags, weights and input order differ: %j', (...items) => {
|
||||
const excluded = new Set<string>();
|
||||
const selected: string[] = [];
|
||||
for (let attempt = 0; attempt <= items.length; attempt += 1) {
|
||||
const next = selectChannelCandidate(items, {
|
||||
carrier: 'mobile',
|
||||
forceNational: true,
|
||||
excludedChannelIds: excluded,
|
||||
approvedChannelIds: new Set(items.map((item) => item.channelId)),
|
||||
routingKey: 'order-verification',
|
||||
});
|
||||
if (!next) break;
|
||||
selected.push(next.channelId);
|
||||
excluded.add(next.channelId);
|
||||
}
|
||||
expect(selected).toEqual(['first', 'middle', 'last']);
|
||||
});
|
||||
|
||||
it('skips ineligible slots without changing the order of remaining eligible channels', () => {
|
||||
const items = [member('offline', 10), member('unreported', 20), member('next', 30, true), member('last', 40)];
|
||||
items[0].channel.connectionStates = [];
|
||||
const options = {
|
||||
carrier: 'mobile',
|
||||
forceNational: true,
|
||||
excludedChannelIds: new Set<string>(),
|
||||
approvedChannelIds: new Set(['offline', 'next', 'last']),
|
||||
};
|
||||
expect(selectChannelCandidate(items, options)?.channelId).toBe('next');
|
||||
options.excludedChannelIds.add('next');
|
||||
expect(selectChannelCandidate(items, options)?.channelId).toBe('last');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user