From 874250137a24506a40474f45498751761e480330 Mon Sep 17 00:00:00 2001 From: Nazareno Bucciarelli Date: Fri, 27 Feb 2026 16:50:19 -0300 Subject: [PATCH 1/2] add sleep between settings updates --- apps/meteor/tests/end-to-end/api/custom-sounds.ts | 14 ++++++++++++-- apps/meteor/tests/end-to-end/api/emoji-custom.ts | 15 +++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/apps/meteor/tests/end-to-end/api/custom-sounds.ts b/apps/meteor/tests/end-to-end/api/custom-sounds.ts index 2abb62b8fae76..860b8a4a470fd 100644 --- a/apps/meteor/tests/end-to-end/api/custom-sounds.ts +++ b/apps/meteor/tests/end-to-end/api/custom-sounds.ts @@ -5,6 +5,7 @@ import path from 'path'; import { expect } from 'chai'; import { before, describe, it, after } from 'mocha'; +import { sleep } from '../../../lib/utils/sleep'; import { getCredentials, api, request, credentials } from '../../data/api-data'; import { updateSetting } from '../../data/permissions.helper'; @@ -258,24 +259,28 @@ describe('[CustomSounds]', () => { describe('Sounds storage settings reactivity', () => { let fsFileId: string; let gridFsFileId: string; + const sleepTime = 100; before(async () => { + await updateSetting('CustomSounds_FileSystemPath', '', false); await updateSetting('CustomSounds_Storage_Type', 'FileSystem'); + await sleep(sleepTime); fsFileId = await insertOrUpdateSound(`${fileName}-3`); await uploadCustomSound(binary, `${fileName}-3`, fsFileId); await updateSetting('CustomSounds_Storage_Type', 'GridFS'); + await sleep(sleepTime); gridFsFileId = await insertOrUpdateSound(`${fileName}-4`); await uploadCustomSound(binary, `${fileName}-4`, gridFsFileId); - - await updateSetting('CustomSounds_FileSystemPath', ''); }); after(async () => { await updateSetting('CustomSounds_Storage_Type', 'FileSystem', false); await updateSetting('CustomSounds_FileSystemPath', ''); + await sleep(sleepTime); await deleteCustomSound(fsFileId); await updateSetting('CustomSounds_Storage_Type', 'GridFS'); + await sleep(sleepTime); await deleteCustomSound(gridFsFileId); }); @@ -283,6 +288,7 @@ describe('[CustomSounds]', () => { describe('when storage is GridFS', () => { before(async () => { await updateSetting('CustomSounds_Storage_Type', 'GridFS'); + await sleep(sleepTime); }); it('should resolve GridFS files only', async () => { @@ -294,6 +300,7 @@ describe('[CustomSounds]', () => { describe('when storage is FileSystem', () => { before(async () => { await updateSetting('CustomSounds_Storage_Type', 'FileSystem'); + await sleep(sleepTime); }); it('should resolve FileSystem files only', async () => { @@ -306,6 +313,7 @@ describe('[CustomSounds]', () => { describe('CustomSounds_FileSystemPath', () => { before(async () => { await updateSetting('CustomSounds_Storage_Type', 'FileSystem'); + await sleep(sleepTime); }); describe('when file system path is the default one', () => { @@ -317,10 +325,12 @@ describe('[CustomSounds]', () => { describe('when file system path is NOT the default one', () => { before(async () => { await updateSetting('CustomSounds_FileSystemPath', '~/sounds'); + await sleep(sleepTime); }); after(async () => { await updateSetting('CustomSounds_FileSystemPath', ''); + await sleep(sleepTime); }); it('should NOT resolve files', async () => { diff --git a/apps/meteor/tests/end-to-end/api/emoji-custom.ts b/apps/meteor/tests/end-to-end/api/emoji-custom.ts index 57ec2570eb200..8f6ee845ea440 100644 --- a/apps/meteor/tests/end-to-end/api/emoji-custom.ts +++ b/apps/meteor/tests/end-to-end/api/emoji-custom.ts @@ -2,6 +2,7 @@ import type { IEmojiCustom } from '@rocket.chat/core-typings'; import { assert, expect } from 'chai'; import { before, describe, it, after } from 'mocha'; +import { sleep } from '../../../lib/utils/sleep'; import { getCredentials, api, request, credentials } from '../../data/api-data'; import { imgURL } from '../../data/interactions'; import { updateSetting } from '../../data/permissions.helper'; @@ -495,15 +496,17 @@ describe('[EmojiCustom]', () => { ? `); + const sleepTime = 100; before(async () => { + await updateSetting('EmojiUpload_FileSystemPath', '', false); await updateSetting('EmojiUpload_Storage_Type', 'FileSystem'); + await sleep(sleepTime); await request.post(api('emoji-custom.create')).set(credentials).attach('emoji', imgURL).field({ name: fsEmojiName }).expect(200); await updateSetting('EmojiUpload_Storage_Type', 'GridFS'); await request.post(api('emoji-custom.create')).set(credentials).attach('emoji', imgURL).field({ name: gridFsEmojiName }).expect(200); - - await updateSetting('EmojiUpload_FileSystemPath', ''); + await sleep(sleepTime); }); after(async () => { @@ -513,11 +516,13 @@ describe('[EmojiCustom]', () => { await updateSetting('EmojiUpload_Storage_Type', 'FileSystem', false); await updateSetting('EmojiUpload_FileSystemPath', ''); + await sleep(sleepTime); if (fsEmoji) { await request.post(api('emoji-custom.delete')).set(credentials).send({ emojiId: fsEmoji._id }); } await updateSetting('EmojiUpload_Storage_Type', 'GridFS'); + await sleep(sleepTime); if (gridEmoji) { await request.post(api('emoji-custom.delete')).set(credentials).send({ emojiId: gridEmoji._id }); } @@ -527,6 +532,7 @@ describe('[EmojiCustom]', () => { describe('when storage is GridFs', () => { before(async () => { await updateSetting('EmojiUpload_Storage_Type', 'GridFS'); + await sleep(sleepTime); }); it('should resolve GridFS files only', async () => { @@ -549,6 +555,7 @@ describe('[EmojiCustom]', () => { describe('when storage is FileSystem', () => { before(async () => { await updateSetting('EmojiUpload_Storage_Type', 'FileSystem'); + await sleep(sleepTime); }); it('should resolve FileSystem files only', async () => { @@ -572,11 +579,13 @@ describe('[EmojiCustom]', () => { describe('EmojiUpload_FileSystemPath', () => { before(async () => { await updateSetting('EmojiUpload_Storage_Type', 'FileSystem'); + await sleep(sleepTime); }); describe('when file system path is the default one', () => { before(async () => { await updateSetting('EmojiUpload_FileSystemPath', ''); + await sleep(sleepTime); }); it('should resolve files', async () => { @@ -591,10 +600,12 @@ describe('[EmojiCustom]', () => { describe('when file system path is NOT the default one', () => { before(async () => { await updateSetting('EmojiUpload_FileSystemPath', '~/emoji-test'); + await sleep(sleepTime); }); after(async () => { await updateSetting('CustomSounds_FileSystemPath', ''); + await sleep(sleepTime); }); it('should NOT resolve files', async () => { From c7212640f91a8d65f662b817654111f8efa82d98 Mon Sep 17 00:00:00 2001 From: Nazareno Bucciarelli Date: Mon, 2 Mar 2026 13:53:11 -0300 Subject: [PATCH 2/2] skip watchMultiple debounce on TEST_MODE=true --- apps/meteor/app/settings/server/CachedSettings.ts | 12 +++++++++--- apps/meteor/tests/end-to-end/api/custom-sounds.ts | 11 ----------- apps/meteor/tests/end-to-end/api/emoji-custom.ts | 12 ------------ 3 files changed, 9 insertions(+), 26 deletions(-) diff --git a/apps/meteor/app/settings/server/CachedSettings.ts b/apps/meteor/app/settings/server/CachedSettings.ts index 3c46dd05a6806..8332f45c5c497 100644 --- a/apps/meteor/app/settings/server/CachedSettings.ts +++ b/apps/meteor/app/settings/server/CachedSettings.ts @@ -181,9 +181,15 @@ export class CachedSettings const settings = _id.map((id) => this.store.get(id)?.value); callback(settings as T[]); } - const mergeFunction = _.debounce((): void => { - callback(_id.map((id) => this.store.get(id)?.value) as T[]); - }, 100); + + const mergeFunction = + process.env.TEST_MODE !== 'true' + ? _.debounce((): void => { + callback(_id.map((id) => this.store.get(id)?.value) as T[]); + }, 100) + : (): void => { + callback(_id.map((id) => this.store.get(id)?.value) as T[]); + }; const fns = _id.map((id) => this.on(id, mergeFunction)); return (): void => { diff --git a/apps/meteor/tests/end-to-end/api/custom-sounds.ts b/apps/meteor/tests/end-to-end/api/custom-sounds.ts index 860b8a4a470fd..b035a5d6fec40 100644 --- a/apps/meteor/tests/end-to-end/api/custom-sounds.ts +++ b/apps/meteor/tests/end-to-end/api/custom-sounds.ts @@ -5,7 +5,6 @@ import path from 'path'; import { expect } from 'chai'; import { before, describe, it, after } from 'mocha'; -import { sleep } from '../../../lib/utils/sleep'; import { getCredentials, api, request, credentials } from '../../data/api-data'; import { updateSetting } from '../../data/permissions.helper'; @@ -259,17 +258,14 @@ describe('[CustomSounds]', () => { describe('Sounds storage settings reactivity', () => { let fsFileId: string; let gridFsFileId: string; - const sleepTime = 100; before(async () => { await updateSetting('CustomSounds_FileSystemPath', '', false); await updateSetting('CustomSounds_Storage_Type', 'FileSystem'); - await sleep(sleepTime); fsFileId = await insertOrUpdateSound(`${fileName}-3`); await uploadCustomSound(binary, `${fileName}-3`, fsFileId); await updateSetting('CustomSounds_Storage_Type', 'GridFS'); - await sleep(sleepTime); gridFsFileId = await insertOrUpdateSound(`${fileName}-4`); await uploadCustomSound(binary, `${fileName}-4`, gridFsFileId); }); @@ -277,10 +273,8 @@ describe('[CustomSounds]', () => { after(async () => { await updateSetting('CustomSounds_Storage_Type', 'FileSystem', false); await updateSetting('CustomSounds_FileSystemPath', ''); - await sleep(sleepTime); await deleteCustomSound(fsFileId); await updateSetting('CustomSounds_Storage_Type', 'GridFS'); - await sleep(sleepTime); await deleteCustomSound(gridFsFileId); }); @@ -288,7 +282,6 @@ describe('[CustomSounds]', () => { describe('when storage is GridFS', () => { before(async () => { await updateSetting('CustomSounds_Storage_Type', 'GridFS'); - await sleep(sleepTime); }); it('should resolve GridFS files only', async () => { @@ -300,7 +293,6 @@ describe('[CustomSounds]', () => { describe('when storage is FileSystem', () => { before(async () => { await updateSetting('CustomSounds_Storage_Type', 'FileSystem'); - await sleep(sleepTime); }); it('should resolve FileSystem files only', async () => { @@ -313,7 +305,6 @@ describe('[CustomSounds]', () => { describe('CustomSounds_FileSystemPath', () => { before(async () => { await updateSetting('CustomSounds_Storage_Type', 'FileSystem'); - await sleep(sleepTime); }); describe('when file system path is the default one', () => { @@ -325,12 +316,10 @@ describe('[CustomSounds]', () => { describe('when file system path is NOT the default one', () => { before(async () => { await updateSetting('CustomSounds_FileSystemPath', '~/sounds'); - await sleep(sleepTime); }); after(async () => { await updateSetting('CustomSounds_FileSystemPath', ''); - await sleep(sleepTime); }); it('should NOT resolve files', async () => { diff --git a/apps/meteor/tests/end-to-end/api/emoji-custom.ts b/apps/meteor/tests/end-to-end/api/emoji-custom.ts index 8f6ee845ea440..b256fd4b54551 100644 --- a/apps/meteor/tests/end-to-end/api/emoji-custom.ts +++ b/apps/meteor/tests/end-to-end/api/emoji-custom.ts @@ -2,7 +2,6 @@ import type { IEmojiCustom } from '@rocket.chat/core-typings'; import { assert, expect } from 'chai'; import { before, describe, it, after } from 'mocha'; -import { sleep } from '../../../lib/utils/sleep'; import { getCredentials, api, request, credentials } from '../../data/api-data'; import { imgURL } from '../../data/interactions'; import { updateSetting } from '../../data/permissions.helper'; @@ -496,17 +495,14 @@ describe('[EmojiCustom]', () => { ? `); - const sleepTime = 100; before(async () => { await updateSetting('EmojiUpload_FileSystemPath', '', false); await updateSetting('EmojiUpload_Storage_Type', 'FileSystem'); - await sleep(sleepTime); await request.post(api('emoji-custom.create')).set(credentials).attach('emoji', imgURL).field({ name: fsEmojiName }).expect(200); await updateSetting('EmojiUpload_Storage_Type', 'GridFS'); await request.post(api('emoji-custom.create')).set(credentials).attach('emoji', imgURL).field({ name: gridFsEmojiName }).expect(200); - await sleep(sleepTime); }); after(async () => { @@ -516,13 +512,11 @@ describe('[EmojiCustom]', () => { await updateSetting('EmojiUpload_Storage_Type', 'FileSystem', false); await updateSetting('EmojiUpload_FileSystemPath', ''); - await sleep(sleepTime); if (fsEmoji) { await request.post(api('emoji-custom.delete')).set(credentials).send({ emojiId: fsEmoji._id }); } await updateSetting('EmojiUpload_Storage_Type', 'GridFS'); - await sleep(sleepTime); if (gridEmoji) { await request.post(api('emoji-custom.delete')).set(credentials).send({ emojiId: gridEmoji._id }); } @@ -532,7 +526,6 @@ describe('[EmojiCustom]', () => { describe('when storage is GridFs', () => { before(async () => { await updateSetting('EmojiUpload_Storage_Type', 'GridFS'); - await sleep(sleepTime); }); it('should resolve GridFS files only', async () => { @@ -555,7 +548,6 @@ describe('[EmojiCustom]', () => { describe('when storage is FileSystem', () => { before(async () => { await updateSetting('EmojiUpload_Storage_Type', 'FileSystem'); - await sleep(sleepTime); }); it('should resolve FileSystem files only', async () => { @@ -579,13 +571,11 @@ describe('[EmojiCustom]', () => { describe('EmojiUpload_FileSystemPath', () => { before(async () => { await updateSetting('EmojiUpload_Storage_Type', 'FileSystem'); - await sleep(sleepTime); }); describe('when file system path is the default one', () => { before(async () => { await updateSetting('EmojiUpload_FileSystemPath', ''); - await sleep(sleepTime); }); it('should resolve files', async () => { @@ -600,12 +590,10 @@ describe('[EmojiCustom]', () => { describe('when file system path is NOT the default one', () => { before(async () => { await updateSetting('EmojiUpload_FileSystemPath', '~/emoji-test'); - await sleep(sleepTime); }); after(async () => { await updateSetting('CustomSounds_FileSystemPath', ''); - await sleep(sleepTime); }); it('should NOT resolve files', async () => {