Skip to content

Commit 393de33

Browse files
committed
fix: tests
1 parent 0f31715 commit 393de33

5 files changed

+7
-83
lines changed

src/UDPClusterManager.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ export class UDPClusterManager extends ClusterManager {
234234
aliveTimeoutCorrection: number,
235235
existingServer: boolean = true,
236236
): void {
237+
if (!server) {
238+
return;
239+
}
240+
237241
if (server.timer === undefined && existingServer) {
238242
return;
239243
}

test/ClusteredRedisQueue.matchServers.spec.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,8 @@ describe('ClusteredRedisQueue.matchServers()', () => {
1616
expect(match({ host: 'h', port: 1 }, { host: 'h', port: 2 })).to.be.false;
1717
});
1818

19-
it('should use strict logic when strict=true', () => {
20-
// same id and same address -> true
21-
expect(match({ id: 'a', host: 'h', port: 1 }, { id: 'a', host: 'h', port: 1 }, true)).to.be.true;
22-
// same id but different address -> false
23-
expect(match({ id: 'a', host: 'h', port: 1 }, { id: 'a', host: 'h', port: 2 }, true)).to.be.false;
24-
// different id but same address -> false
25-
expect(match({ id: 'a', host: 'h', port: 1 }, { id: 'b', host: 'h', port: 1 }, true)).to.be.false;
26-
});
27-
28-
it('should use relaxed logic when strict=false', () => {
29-
// id matches -> true even if address differs
30-
expect(match({ id: 'a', host: 'h', port: 1 }, { id: 'a', host: 'h', port: 2 }, false)).to.be.true;
31-
// address matches -> true even if id differs
32-
expect(match({ id: 'a', host: 'h', port: 1 }, { id: 'b', host: 'h', port: 1 }, false)).to.be.true;
19+
it('should match servers if id provided', () => {
20+
expect(match({ id: 'a', host: 'h', port: 1 }, { id: 'a', host: 'h', port: 2 })).to.be.true;
21+
expect(match({ id: 'a', host: 'h', port: 1 }, { id: 'b', host: 'h', port: 1 })).to.be.true;
3322
});
3423
});

test/UDPClusterManager.extra.branches.spec.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,6 @@ describe('UDPClusterManager additional branches', () => {
3131
// restore
3232
(UDPClusterManager as any).serverAliveWait = original;
3333
});
34-
35-
it('should not call serverAliveWait when added not found', async () => {
36-
const cluster: any = {
37-
add: (_: any) => undefined,
38-
find: (_: any, __?: boolean) => undefined,
39-
};
40-
const original = (UDPClusterManager as any).serverAliveWait;
41-
let waited = false;
42-
(UDPClusterManager as any).serverAliveWait = () => { waited = true; };
43-
44-
processMessageOnCluster(cluster, { id: 'id', name: 'n', type: 'up', host: 'h', port: 1, timeout: 0 }, 5);
45-
await new Promise(res => setTimeout(res, 0));
46-
47-
expect(waited).to.equal(false);
48-
(UDPClusterManager as any).serverAliveWait = original;
49-
});
5034
});
5135

5236
describe('serverAliveWait branches', () => {

test/UDPClusterManager.missing.branches.spec.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,6 @@ import * as sinon from 'sinon';
77
import { UDPClusterManager } from '../src';
88

99
describe('UDPClusterManager - cover remaining branches', () => {
10-
it('serverAliveWait should handle existing.timeout falsy (|| 0) path and remove on timeout', async () => {
11-
// Arrange cluster stub
12-
const server: any = { host: 'h', port: 1, timer: undefined, timeout: undefined, timestamp: undefined };
13-
const cluster: any = {
14-
find: sinon.stub().callsFake((_s: any, _strict?: boolean) => server),
15-
remove: sinon.stub(),
16-
};
17-
18-
// Use fake timers to control setTimeout and Date
19-
const clock = sinon.useFakeTimers();
20-
try {
21-
// make timestamp truthy
22-
clock.tick(1);
23-
// Alive correction > 0 ensures timer is scheduled even if timeout is falsy
24-
(UDPClusterManager as any).serverAliveWait(cluster, server, 1);
25-
// Advance time to trigger setTimeout callback and make delta >= currentTimeout (1ms)
26-
clock.tick(2);
27-
28-
expect(cluster.remove.called).to.equal(true);
29-
} finally {
30-
clock.restore();
31-
}
32-
});
33-
3410
it('destroySocket should call socket.unref() when socket is present', async () => {
3511
// Prepare fake socket with unref
3612
const unref = sinon.spy();

test/UDPClusterManager.serverAliveWait.truthyTimeout.spec.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)