From 0a7b2004d2389a15daaae4f1043d27c8d037fbea Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Mon, 10 Feb 2025 07:46:44 +0000 Subject: [PATCH] [misc] silence logger when running tests (#22243) * [misc] silence logger when running tests * [misc] re-enable logging in some tests for scripts * [misc] make it easy to turn on verbose logging for tests ``` LOG_LEVEL=debug make test_unit LOG_LEVEL=debug make test_acceptance ``` GitOrigin-RevId: 219bc6d1f9cbdb89ddd7d94742920913ddde4514 --- libraries/logger/logging-manager.js | 4 +++- services/chat/docker-compose.yml | 3 ++- services/clsi/docker-compose.yml | 3 ++- services/clsi/test/acceptance/js/helpers/ClsiApp.js | 3 --- services/contacts/docker-compose.yml | 3 ++- services/docstore/docker-compose.yml | 3 ++- services/docstore/test/acceptance/js/helpers/DocstoreApp.js | 1 - services/document-updater/docker-compose.yml | 3 ++- .../test/acceptance/js/helpers/DocUpdaterApp.js | 1 - services/filestore/docker-compose.yml | 3 ++- services/filestore/test/acceptance/js/FilestoreApp.js | 3 --- services/history-v1/docker-compose.yml | 3 ++- .../test/acceptance/js/api/backupVerifier.test.mjs | 5 ++++- services/notifications/docker-compose.yml | 3 ++- services/project-history/docker-compose.yml | 3 ++- .../test/acceptance/js/helpers/ProjectHistoryApp.js | 2 -- services/real-time/docker-compose.yml | 3 ++- services/web/docker-compose.ci.yml | 1 + services/web/docker-compose.yml | 3 +++ .../test/acceptance/src/ServerCEScriptsTests.mjs | 4 ++++ services/web/test/acceptance/src/helpers/InitApp.mjs | 3 --- 21 files changed, 35 insertions(+), 25 deletions(-) diff --git a/libraries/logger/logging-manager.js b/libraries/logger/logging-manager.js index 7bfad1aa5e..edf922be72 100644 --- a/libraries/logger/logging-manager.js +++ b/libraries/logger/logging-manager.js @@ -14,8 +14,10 @@ const LoggingManager = { initialize(name) { this.isProduction = (process.env.NODE_ENV || '').toLowerCase() === 'production' + const isTest = (process.env.NODE_ENV || '').toLowerCase() === 'test' this.defaultLevel = - process.env.LOG_LEVEL || (this.isProduction ? 'info' : 'debug') + process.env.LOG_LEVEL || + (this.isProduction ? 'info' : isTest ? 'fatal' : 'debug') this.loggerName = name this.logger = bunyan.createLogger({ name, diff --git a/services/chat/docker-compose.yml b/services/chat/docker-compose.yml index 72e0de6e6f..8fec13cbb2 100644 --- a/services/chat/docker-compose.yml +++ b/services/chat/docker-compose.yml @@ -14,6 +14,7 @@ services: working_dir: /overleaf/services/chat environment: MOCHA_GREP: ${MOCHA_GREP} + LOG_LEVEL: ${LOG_LEVEL:-} NODE_ENV: test NODE_OPTIONS: "--unhandled-rejections=strict" command: npm run --silent test:unit @@ -31,7 +32,7 @@ services: MONGO_HOST: mongo POSTGRES_HOST: postgres MOCHA_GREP: ${MOCHA_GREP} - LOG_LEVEL: ERROR + LOG_LEVEL: ${LOG_LEVEL:-} NODE_ENV: test NODE_OPTIONS: "--unhandled-rejections=strict" user: node diff --git a/services/clsi/docker-compose.yml b/services/clsi/docker-compose.yml index c72fb8b2c4..a525c6029e 100644 --- a/services/clsi/docker-compose.yml +++ b/services/clsi/docker-compose.yml @@ -17,6 +17,7 @@ services: working_dir: /overleaf/services/clsi environment: MOCHA_GREP: ${MOCHA_GREP} + LOG_LEVEL: ${LOG_LEVEL:-} NODE_ENV: test NODE_OPTIONS: "--unhandled-rejections=strict" command: npm run --silent test:unit @@ -37,7 +38,7 @@ services: MONGO_HOST: mongo POSTGRES_HOST: postgres MOCHA_GREP: ${MOCHA_GREP} - LOG_LEVEL: ERROR + LOG_LEVEL: ${LOG_LEVEL:-} NODE_ENV: test NODE_OPTIONS: "--unhandled-rejections=strict" ENABLE_PDF_CACHING: "true" diff --git a/services/clsi/test/acceptance/js/helpers/ClsiApp.js b/services/clsi/test/acceptance/js/helpers/ClsiApp.js index 4736315df8..38308e9129 100644 --- a/services/clsi/test/acceptance/js/helpers/ClsiApp.js +++ b/services/clsi/test/acceptance/js/helpers/ClsiApp.js @@ -10,8 +10,6 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const app = require('../../../../app') -require('@overleaf/logger').logger.level('info') -const logger = require('@overleaf/logger') const Settings = require('@overleaf/settings') module.exports = { @@ -37,7 +35,6 @@ module.exports = { throw error } this.running = true - logger.info('clsi running in dev mode') return (() => { const result = [] diff --git a/services/contacts/docker-compose.yml b/services/contacts/docker-compose.yml index 01cc26cffe..8cdedbe1ef 100644 --- a/services/contacts/docker-compose.yml +++ b/services/contacts/docker-compose.yml @@ -14,6 +14,7 @@ services: working_dir: /overleaf/services/contacts environment: MOCHA_GREP: ${MOCHA_GREP} + LOG_LEVEL: ${LOG_LEVEL:-} NODE_ENV: test NODE_OPTIONS: "--unhandled-rejections=strict" command: npm run --silent test:unit @@ -31,7 +32,7 @@ services: MONGO_HOST: mongo POSTGRES_HOST: postgres MOCHA_GREP: ${MOCHA_GREP} - LOG_LEVEL: ERROR + LOG_LEVEL: ${LOG_LEVEL:-} NODE_ENV: test NODE_OPTIONS: "--unhandled-rejections=strict" user: node diff --git a/services/docstore/docker-compose.yml b/services/docstore/docker-compose.yml index e7f0cc50fd..b170934f48 100644 --- a/services/docstore/docker-compose.yml +++ b/services/docstore/docker-compose.yml @@ -14,6 +14,7 @@ services: working_dir: /overleaf/services/docstore environment: MOCHA_GREP: ${MOCHA_GREP} + LOG_LEVEL: ${LOG_LEVEL:-} NODE_ENV: test NODE_OPTIONS: "--unhandled-rejections=strict" command: npm run --silent test:unit @@ -34,7 +35,7 @@ services: GCS_PROJECT_ID: fake STORAGE_EMULATOR_HOST: http://gcs:9090/storage/v1 MOCHA_GREP: ${MOCHA_GREP} - LOG_LEVEL: ERROR + LOG_LEVEL: ${LOG_LEVEL:-} NODE_ENV: test NODE_OPTIONS: "--unhandled-rejections=strict" user: node diff --git a/services/docstore/test/acceptance/js/helpers/DocstoreApp.js b/services/docstore/test/acceptance/js/helpers/DocstoreApp.js index 03db0ea322..5e837b1277 100644 --- a/services/docstore/test/acceptance/js/helpers/DocstoreApp.js +++ b/services/docstore/test/acceptance/js/helpers/DocstoreApp.js @@ -1,5 +1,4 @@ const app = require('../../../../app') -require('@overleaf/logger').logger.level('error') const settings = require('@overleaf/settings') module.exports = { diff --git a/services/document-updater/docker-compose.yml b/services/document-updater/docker-compose.yml index e211782e08..7770e52d26 100644 --- a/services/document-updater/docker-compose.yml +++ b/services/document-updater/docker-compose.yml @@ -14,6 +14,7 @@ services: working_dir: /overleaf/services/document-updater environment: MOCHA_GREP: ${MOCHA_GREP} + LOG_LEVEL: ${LOG_LEVEL:-} NODE_ENV: test NODE_OPTIONS: "--unhandled-rejections=strict" command: npm run --silent test:unit @@ -34,7 +35,7 @@ services: MONGO_HOST: mongo POSTGRES_HOST: postgres MOCHA_GREP: ${MOCHA_GREP} - LOG_LEVEL: ERROR + LOG_LEVEL: ${LOG_LEVEL:-} NODE_ENV: test NODE_OPTIONS: "--unhandled-rejections=strict" user: node diff --git a/services/document-updater/test/acceptance/js/helpers/DocUpdaterApp.js b/services/document-updater/test/acceptance/js/helpers/DocUpdaterApp.js index 33c6882138..d34996ca7c 100644 --- a/services/document-updater/test/acceptance/js/helpers/DocUpdaterApp.js +++ b/services/document-updater/test/acceptance/js/helpers/DocUpdaterApp.js @@ -9,7 +9,6 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const app = require('../../../../app') -require('@overleaf/logger').logger.level('fatal') module.exports = { running: false, diff --git a/services/filestore/docker-compose.yml b/services/filestore/docker-compose.yml index 594cdaf9c9..cc58997445 100644 --- a/services/filestore/docker-compose.yml +++ b/services/filestore/docker-compose.yml @@ -17,6 +17,7 @@ services: working_dir: /overleaf/services/filestore environment: MOCHA_GREP: ${MOCHA_GREP} + LOG_LEVEL: ${LOG_LEVEL:-} NODE_ENV: test NODE_OPTIONS: "--unhandled-rejections=strict" command: npm run --silent test:unit @@ -47,7 +48,7 @@ services: GCS_PROJECT_ID: fake STORAGE_EMULATOR_HOST: http://gcs:9090/storage/v1 MOCHA_GREP: ${MOCHA_GREP} - LOG_LEVEL: ERROR + LOG_LEVEL: ${LOG_LEVEL:-} NODE_ENV: test NODE_OPTIONS: "--unhandled-rejections=strict" ENABLE_CONVERSIONS: "true" diff --git a/services/filestore/test/acceptance/js/FilestoreApp.js b/services/filestore/test/acceptance/js/FilestoreApp.js index afcebb4c95..61e9a29b7d 100644 --- a/services/filestore/test/acceptance/js/FilestoreApp.js +++ b/services/filestore/test/acceptance/js/FilestoreApp.js @@ -1,12 +1,9 @@ -const logger = require('@overleaf/logger') const ObjectPersistor = require('@overleaf/object-persistor') const Settings = require('@overleaf/settings') const { promisify } = require('node:util') const App = require('../../../app') const FileHandler = require('../../../app/js/FileHandler') -logger.logger.level('info') - class FilestoreApp { async runServer() { if (!this.server) { diff --git a/services/history-v1/docker-compose.yml b/services/history-v1/docker-compose.yml index 26a99e8be1..5eff7b90c1 100644 --- a/services/history-v1/docker-compose.yml +++ b/services/history-v1/docker-compose.yml @@ -17,6 +17,7 @@ services: working_dir: /overleaf/services/history-v1 environment: MOCHA_GREP: ${MOCHA_GREP} + LOG_LEVEL: ${LOG_LEVEL:-} NODE_ENV: test NODE_OPTIONS: "--unhandled-rejections=strict" command: npm run --silent test:unit @@ -47,7 +48,7 @@ services: GCS_PROJECT_ID: fake STORAGE_EMULATOR_HOST: http://gcs:9090/storage/v1 MOCHA_GREP: ${MOCHA_GREP} - LOG_LEVEL: ERROR + LOG_LEVEL: ${LOG_LEVEL:-} NODE_ENV: test NODE_OPTIONS: "--unhandled-rejections=strict" user: node diff --git a/services/history-v1/test/acceptance/js/api/backupVerifier.test.mjs b/services/history-v1/test/acceptance/js/api/backupVerifier.test.mjs index af041b0d7a..54a801a919 100644 --- a/services/history-v1/test/acceptance/js/api/backupVerifier.test.mjs +++ b/services/history-v1/test/acceptance/js/api/backupVerifier.test.mjs @@ -40,7 +40,10 @@ async function verifyBlobScript(historyId, hash) { { encoding: 'utf-8', timeout: 5_000, - env: process.env, + env: { + ...process.env, + LOG_LEVEL: 'warn', + }, } ) return { status: 0, stdout: result.stdout } diff --git a/services/notifications/docker-compose.yml b/services/notifications/docker-compose.yml index 11266cbad0..ba54a3d38e 100644 --- a/services/notifications/docker-compose.yml +++ b/services/notifications/docker-compose.yml @@ -14,6 +14,7 @@ services: working_dir: /overleaf/services/notifications environment: MOCHA_GREP: ${MOCHA_GREP} + LOG_LEVEL: ${LOG_LEVEL:-} NODE_ENV: test NODE_OPTIONS: "--unhandled-rejections=strict" command: npm run --silent test:unit @@ -31,7 +32,7 @@ services: MONGO_HOST: mongo POSTGRES_HOST: postgres MOCHA_GREP: ${MOCHA_GREP} - LOG_LEVEL: ERROR + LOG_LEVEL: ${LOG_LEVEL:-} NODE_ENV: test NODE_OPTIONS: "--unhandled-rejections=strict" user: node diff --git a/services/project-history/docker-compose.yml b/services/project-history/docker-compose.yml index 2646042efc..c5b410b4fd 100644 --- a/services/project-history/docker-compose.yml +++ b/services/project-history/docker-compose.yml @@ -14,6 +14,7 @@ services: working_dir: /overleaf/services/project-history environment: MOCHA_GREP: ${MOCHA_GREP} + LOG_LEVEL: ${LOG_LEVEL:-} NODE_ENV: test NODE_OPTIONS: "--unhandled-rejections=strict" command: npm run --silent test:unit @@ -34,7 +35,7 @@ services: MONGO_HOST: mongo POSTGRES_HOST: postgres MOCHA_GREP: ${MOCHA_GREP} - LOG_LEVEL: ERROR + LOG_LEVEL: ${LOG_LEVEL:-} NODE_ENV: test NODE_OPTIONS: "--unhandled-rejections=strict" user: node diff --git a/services/project-history/test/acceptance/js/helpers/ProjectHistoryApp.js b/services/project-history/test/acceptance/js/helpers/ProjectHistoryApp.js index 4fb9993c63..ae453b74f9 100644 --- a/services/project-history/test/acceptance/js/helpers/ProjectHistoryApp.js +++ b/services/project-history/test/acceptance/js/helpers/ProjectHistoryApp.js @@ -9,8 +9,6 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import { app } from '../../../../app/js/server.js' -import logger from '@overleaf/logger' -logger.logger.level('error') let running = false let initing = false diff --git a/services/real-time/docker-compose.yml b/services/real-time/docker-compose.yml index 2e30534c0b..5ff5afe513 100644 --- a/services/real-time/docker-compose.yml +++ b/services/real-time/docker-compose.yml @@ -14,6 +14,7 @@ services: working_dir: /overleaf/services/real-time environment: MOCHA_GREP: ${MOCHA_GREP} + LOG_LEVEL: ${LOG_LEVEL:-} NODE_ENV: test NODE_OPTIONS: "--unhandled-rejections=strict" command: npm run --silent test:unit @@ -34,7 +35,7 @@ services: MONGO_HOST: mongo POSTGRES_HOST: postgres MOCHA_GREP: ${MOCHA_GREP} - LOG_LEVEL: ERROR + LOG_LEVEL: ${LOG_LEVEL:-} NODE_ENV: test NODE_OPTIONS: "--unhandled-rejections=strict" user: node diff --git a/services/web/docker-compose.ci.yml b/services/web/docker-compose.ci.yml index fb13cd8977..a8a9f4b5a1 100644 --- a/services/web/docker-compose.ci.yml +++ b/services/web/docker-compose.ci.yml @@ -17,6 +17,7 @@ services: environment: BASE_CONFIG: OVERLEAF_CONFIG: + NODE_ENV: test NODE_OPTIONS: "--unhandled-rejections=strict" depends_on: - mongo diff --git a/services/web/docker-compose.yml b/services/web/docker-compose.yml index 74ed5c2e53..8594d9442a 100644 --- a/services/web/docker-compose.yml +++ b/services/web/docker-compose.yml @@ -17,6 +17,8 @@ services: BASE_CONFIG: OVERLEAF_CONFIG: MOCHA_GREP: ${MOCHA_GREP} + LOG_LEVEL: ${LOG_LEVEL:-} + NODE_ENV: test NODE_OPTIONS: "--unhandled-rejections=strict" command: npm run --silent test:unit:app user: node @@ -36,6 +38,7 @@ services: BASE_CONFIG: OVERLEAF_CONFIG: MOCHA_GREP: ${MOCHA_GREP} + LOG_LEVEL: ${LOG_LEVEL:-} MONGO_SERVER_SELECTION_TIMEOUT: 600000 MONGO_SOCKET_TIMEOUT: 300000 # OVERLEAF_ALLOW_ANONYMOUS_READ_AND_WRITE_SHARING: 'true' diff --git a/services/web/modules/server-ce-scripts/test/acceptance/src/ServerCEScriptsTests.mjs b/services/web/modules/server-ce-scripts/test/acceptance/src/ServerCEScriptsTests.mjs index afa6ec4137..c381159e43 100644 --- a/services/web/modules/server-ce-scripts/test/acceptance/src/ServerCEScriptsTests.mjs +++ b/services/web/modules/server-ce-scripts/test/acceptance/src/ServerCEScriptsTests.mjs @@ -19,6 +19,10 @@ function run(cmd) { // Pipe stdin from /dev/null, store stdout, pipe stderr to /dev/null. return execSync(cmd, { stdio: ['ignore', 'pipe', 'pipe'], + env: { + ...process.env, + LOG_LEVEL: 'warn', + }, }).toString() } diff --git a/services/web/test/acceptance/src/helpers/InitApp.mjs b/services/web/test/acceptance/src/helpers/InitApp.mjs index 5fa6d44040..d1ea137fef 100644 --- a/services/web/test/acceptance/src/helpers/InitApp.mjs +++ b/services/web/test/acceptance/src/helpers/InitApp.mjs @@ -2,7 +2,6 @@ import App from '../../../../app.mjs' import QueueWorkers from '../../../../app/src/infrastructure/QueueWorkers.js' import MongoHelper from './MongoHelper.mjs' import RedisHelper from './RedisHelper.mjs' -import logger from '@overleaf/logger' import Settings from '@overleaf/settings' import MockReCAPTCHAApi from '../mocks/MockReCaptchaApi.mjs' import { gracefulShutdown } from '../../../../app/src/infrastructure/GracefulShutdown.js' @@ -14,8 +13,6 @@ import Modules from '../../../../app/src/infrastructure/Modules.js' const app = Server.app -logger.logger.level('error') - MongoHelper.initialize() RedisHelper.initialize() MockReCAPTCHAApi.initialize(2222)