Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/throttledQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions tests/cgateConnectionPool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -82,6 +82,7 @@ describe('CgateConnectionPool', () => {
if (pool.isStarted) {
await pool.stop();
}
jest.useRealTimers();
});

describe('Constructor', () => {
Expand Down
10 changes: 10 additions & 0 deletions tests/config/configLoader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);

Expand Down
5 changes: 3 additions & 2 deletions tests/throttledQueue.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Loading