diff --git a/src/throttledQueue.js b/src/throttledQueue.js index 6022aef..243eb52 100644 --- a/src/throttledQueue.js +++ b/src/throttledQueue.js @@ -9,7 +9,7 @@ class ThrottledQueue { * @param {number} intervalMs - Minimum interval between processing items * @param {string} name - Queue name for logging * @param {Object} [options] - Additional options - * @param {number} [options.maxSize=1000] - Maximum queue size (0 = unlimited) + * @param {number} [options.maxSize] - Maximum queue size (0 = unlimited; default: schema maxQueueSize) * @param {Function} [options.getIntervalMs] - Dynamic interval override; returns the delay before processing the next item * @param {Function} [options.canProcessFn] - Gate checked before each item; processing retries when it returns false * @param {number} [options.retryWhenBlockedMs] - Delay before retrying when canProcessFn blocks processing @@ -47,7 +47,7 @@ class ThrottledQueue { this._active = false; this._length = 0; this._name = name; - this._maxSize = options.maxSize !== undefined ? options.maxSize : 1000; + this._maxSize = options.maxSize !== undefined ? options.maxSize : resolveSetting({}, 'maxQueueSize'); this._getIntervalMs = typeof options.getIntervalMs === 'function' ? options.getIntervalMs : null; this._canProcessFn = typeof options.canProcessFn === 'function' ? options.canProcessFn : null; const retryMinMs = options.retryWhenBlockedMinMs !== undefined diff --git a/tests/cgateConnectionPool.test.js b/tests/cgateConnectionPool.test.js index 1184c96..9bcb864 100644 --- a/tests/cgateConnectionPool.test.js +++ b/tests/cgateConnectionPool.test.js @@ -12,9 +12,6 @@ jest.mock('net', () => ({ createConnection: jest.fn() })); -// Mock timers -jest.useFakeTimers(); - /** * Creates a mock CgateConnection that emits 'connect' asynchronously. * Pass { failConnect: true } to emit 'error' instead. @@ -51,6 +48,9 @@ describe('CgateConnectionPool', () => { let randomSpy; beforeEach(() => { + // Per-test timers, not module-scope: a leftover useFakeTimers() here + // used to leak into later files that need real clocks (labelLoader watch). + jest.useFakeTimers(); jest.clearAllMocks(); jest.clearAllTimers(); randomSpy = jest.spyOn(Math, 'random').mockReturnValue(0.5); @@ -82,6 +82,7 @@ describe('CgateConnectionPool', () => { if (pool.isStarted) { await pool.stop(); } + jest.useRealTimers(); }); describe('Constructor', () => { diff --git a/tests/config/configLoader.test.js b/tests/config/configLoader.test.js index 6683eac..6fbc623 100644 --- a/tests/config/configLoader.test.js +++ b/tests/config/configLoader.test.js @@ -601,7 +601,12 @@ describe('ConfigLoader', () => { ha_discovery_enabled: false }; + let originalResolve; + let originalCache; + beforeEach(() => { + originalResolve = require.resolve; + originalCache = require.cache; mockEnvironmentDetector.detect.mockReturnValue({ type: 'standalone', isAddon: false, @@ -611,6 +616,11 @@ describe('ConfigLoader', () => { }); }); + afterEach(() => { + require.resolve = originalResolve; + require.cache = originalCache; + }); + test('should load standalone configuration from settings.js', () => { fs.existsSync.mockReturnValue(true); diff --git a/tests/throttledQueue.test.js b/tests/throttledQueue.test.js index e6ed7e6..4b6318e 100644 --- a/tests/throttledQueue.test.js +++ b/tests/throttledQueue.test.js @@ -241,9 +241,10 @@ describe('ThrottledQueue', () => { }); describe('Queue size limits', () => { - it('should default to maxSize of 1000', () => { + it('should default to the schema maxQueueSize', () => { + const { resolveSetting } = require('../src/config/schema'); const queue = new ThrottledQueue(jest.fn(), 100); - expect(queue.maxSize).toBe(1000); + expect(queue.maxSize).toBe(resolveSetting({}, 'maxQueueSize')); }); it('should accept custom maxSize', () => {