feat: add test for unchanged candidates when avoidSec is omitted and improve condition check in filterRecentlyFailedCandidates
This commit is contained in:
@@ -76,6 +76,29 @@ describe('filterRecentlyFailedCandidates', () => {
|
|||||||
expect(result.map((c) => c.id).sort()).toEqual(['a', 'b']);
|
expect(result.map((c) => c.id).sort()).toEqual(['a', 'b']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('keeps candidates unchanged when avoidSec is omitted', () => {
|
||||||
|
const nowMs = Date.now();
|
||||||
|
const candidates: Candidate[] = [
|
||||||
|
{
|
||||||
|
id: 'recent-failure',
|
||||||
|
channel: {
|
||||||
|
failCount: 3,
|
||||||
|
lastFailAt: new Date(nowMs - 5 * 1000).toISOString(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'healthy',
|
||||||
|
channel: {
|
||||||
|
failCount: 0,
|
||||||
|
lastFailAt: null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const result = filterRecentlyFailedCandidates(candidates, nowMs);
|
||||||
|
expect(result).toEqual(candidates);
|
||||||
|
});
|
||||||
|
|
||||||
it('does not penalize stale failures outside the avoidance window', () => {
|
it('does not penalize stale failures outside the avoidance window', () => {
|
||||||
const nowMs = Date.now();
|
const nowMs = Date.now();
|
||||||
const candidates: Candidate[] = [
|
const candidates: Candidate[] = [
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ export function filterRecentlyFailedCandidates<T extends { channel: FailureAware
|
|||||||
avoidSec?: number,
|
avoidSec?: number,
|
||||||
): T[] {
|
): T[] {
|
||||||
if (candidates.length <= 1) return candidates;
|
if (candidates.length <= 1) return candidates;
|
||||||
if (avoidSec <= 0) return candidates;
|
if (avoidSec == null || avoidSec <= 0) return candidates;
|
||||||
|
|
||||||
const healthy = candidates.filter((candidate) => !isChannelRecentlyFailed(candidate.channel, nowMs, avoidSec));
|
const healthy = candidates.filter((candidate) => !isChannelRecentlyFailed(candidate.channel, nowMs, avoidSec));
|
||||||
// If all channels failed recently, keep them all and let weight/random decide.
|
// If all channels failed recently, keep them all and let weight/random decide.
|
||||||
|
|||||||
Reference in New Issue
Block a user