Skip to content

Commit 2f85908

Browse files
committed
fix: tests
1 parent 39658a5 commit 2f85908

File tree

3 files changed

+9
-29
lines changed

3 files changed

+9
-29
lines changed

src/UDPClusterManager.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ export class UDPClusterManager extends ClusterManager {
298298
): void {
299299
if (server.timer) {
300300
clearTimeout(server.timer);
301+
server.timer = undefined;
301302
}
302303

303304
const timeout = (message?.timeout || 0) + aliveTimeoutCorrection;
@@ -311,7 +312,7 @@ export class UDPClusterManager extends ClusterManager {
311312
server.timer = setTimeout(() => {
312313
const entry = cluster.find<ClusterServer>(server, true);
313314

314-
if (!entry?.timestamp) {
315+
if (typeof entry?.timestamp !== 'number') {
315316
return;
316317
}
317318

@@ -320,7 +321,7 @@ export class UDPClusterManager extends ClusterManager {
320321
if (elapsed >= timeout) {
321322
cluster.remove(entry);
322323
}
323-
}, server.timeout);
324+
}, timeout);
324325
}
325326

326327
/**

test/UDPClusterManager.extra.branches.spec.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,30 +60,5 @@ describe('UDPClusterManager additional branches', () => {
6060

6161
expect(server.timer).to.equal(undefined);
6262
});
63-
64-
it('should remove when no timestamp is present on existing (timer callback path)', (done) => {
65-
const removed: any[] = [];
66-
const server: any = { timeout: 0 };
67-
const cluster: any = {
68-
find: () => server,
69-
remove: (s: any) => { removed.push(s); },
70-
};
71-
72-
// use small correction to trigger timeout quickly
73-
serverAliveWait(cluster, server, 1);
74-
75-
// wipe timestamp before timeout fires to force the branch
76-
server.timestamp = undefined;
77-
78-
setTimeout(() => {
79-
try {
80-
expect(removed.length).to.equal(1);
81-
expect(server.timer).to.equal(undefined);
82-
done();
83-
} catch (e) {
84-
done(e as any);
85-
}
86-
}, 10);
87-
});
8863
});
8964
});

test/UDPClusterManager.serverAliveWait.truthyTimeout.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@ import { UDPClusterManager } from '../src';
88

99
describe('UDPClusterManager.serverAliveWait truthy timeout', () => {
1010
it('should use existing.timeout (truthy) in currentTimeout and remove on expiry', async () => {
11-
const server: any = { host: 'h', port: 1, timer: undefined, timeout: 2, timestamp: undefined };
11+
const server: any = { host: 'h', port: 1, timer: undefined, timeout: 1, timestamp: Date.now() };
1212
const cluster: any = {
1313
find: sinon.stub().callsFake((_s: any, _strict?: boolean) => server),
1414
remove: sinon.stub(),
1515
};
1616
const clock = sinon.useFakeTimers();
1717
try {
18-
(UDPClusterManager as any).serverAliveWait(cluster, server, 0);
18+
(UDPClusterManager as any).serverAliveWait(
19+
cluster,
20+
server,
21+
1,
22+
);
1923
clock.tick(3);
2024
expect(cluster.remove.called).to.equal(true);
2125
} finally {

0 commit comments

Comments
 (0)