From b011440a767fd89b8f49794643127dca39ad9e29 Mon Sep 17 00:00:00 2001 From: DavertMik Date: Fri, 10 Jan 2025 02:19:48 +0200 Subject: [PATCH 1/3] added logs for global timeout --- lib/listener/globalTimeout.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/listener/globalTimeout.js b/lib/listener/globalTimeout.js index 0aad80c9f..c84519584 100644 --- a/lib/listener/globalTimeout.js +++ b/lib/listener/globalTimeout.js @@ -3,6 +3,7 @@ const output = require('../output') const recorder = require('../recorder') const Config = require('../config') const { timeouts } = require('../store') +const debug = require('debug')('codeceptjs:timeout') const TIMEOUT_ORDER = require('../step').TIMEOUT_ORDER module.exports = function () { @@ -20,6 +21,8 @@ module.exports = function () { suiteTimeout = [] let timeoutConfig = Config.get('timeout') + debug('config:', timeoutConfig || 'none') + if (timeoutConfig) { if (!Number.isNaN(+timeoutConfig)) { checkForSeconds(timeoutConfig) @@ -38,8 +41,10 @@ module.exports = function () { } } + debug('current suite timeout:', suite.totalTimeout || 'none') if (suite.totalTimeout) suiteTimeout.push(suite.totalTimeout) output.log(`Timeouts: ${suiteTimeout}`) + debug('active timeouts', suiteTimeout) }) event.dispatcher.on(event.test.before, test => { @@ -81,8 +86,10 @@ module.exports = function () { if (typeof timeout !== 'number') return if (timeout < 0) { + debug('Previous steps timed out, setting timeout to 0.01s') step.setTimeout(0.01, TIMEOUT_ORDER.testOrSuite) } else { + debug(`Setting timeout ${timeout}ms for step ${step.toCode().trim()}`) step.setTimeout(timeout, TIMEOUT_ORDER.testOrSuite) } }) @@ -91,7 +98,9 @@ module.exports = function () { if (typeof timeout === 'number' && !Number.isNaN(timeout)) timeout -= step.duration if (typeof timeout === 'number' && timeout <= 0 && recorder.isRunning()) { + debug(`step ${step.toCode().trim()} timed out`) if (currentTest && currentTest.callback) { + debug(`Failing test ${currentTest.title} with timeout ${currentTimeout}s`) recorder.reset() // replace mocha timeout with custom timeout currentTest.timeout(0) From c982bf3a45a1724d2dbab835198edf01c6ac4455 Mon Sep 17 00:00:00 2001 From: DavertMik Date: Tue, 14 Jan 2025 02:28:55 +0200 Subject: [PATCH 2/3] added debug info and removed timeout for before/after suite hooks --- lib/listener/globalTimeout.js | 40 +++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/lib/listener/globalTimeout.js b/lib/listener/globalTimeout.js index c84519584..ae7510eca 100644 --- a/lib/listener/globalTimeout.js +++ b/lib/listener/globalTimeout.js @@ -2,9 +2,10 @@ const event = require('../event') const output = require('../output') const recorder = require('../recorder') const Config = require('../config') -const { timeouts } = require('../store') +const store = require('../store') const debug = require('debug')('codeceptjs:timeout') const TIMEOUT_ORDER = require('../step').TIMEOUT_ORDER +const { BeforeSuiteHook, AfterSuiteHook } = require('../mocha/hooks') module.exports = function () { let timeout @@ -12,18 +13,28 @@ module.exports = function () { let currentTest let currentTimeout - if (!timeouts) { + if (!store.timeouts) { console.log('Timeouts were disabled') return } + // disable timeout for BeforeSuite/AfterSuite hooks + // add separate configs to them? + event.dispatcher.on(event.hook.started, hook => { + if (hook instanceof BeforeSuiteHook) { + suiteTimeout = [] + } + if (hook instanceof AfterSuiteHook) { + suiteTimeout = [] + } + }) + event.dispatcher.on(event.suite.before, suite => { suiteTimeout = [] let timeoutConfig = Config.get('timeout') - debug('config:', timeoutConfig || 'none') - if (timeoutConfig) { + debug('config:', timeoutConfig) if (!Number.isNaN(+timeoutConfig)) { checkForSeconds(timeoutConfig) suiteTimeout.push(timeoutConfig) @@ -41,10 +52,10 @@ module.exports = function () { } } - debug('current suite timeout:', suite.totalTimeout || 'none') if (suite.totalTimeout) suiteTimeout.push(suite.totalTimeout) output.log(`Timeouts: ${suiteTimeout}`) - debug('active timeouts', suiteTimeout) + + if (suiteTimeout.length > 0) debug(suite.title, 'timeout', suiteTimeout) }) event.dispatcher.on(event.test.before, test => { @@ -69,6 +80,13 @@ module.exports = function () { timeout = test.totalTimeout || testTimeout || suiteTimeout[suiteTimeout.length - 1] if (!timeout) return + + debug(test.title, 'timeout', { + 'config from file': testTimeout, + 'suite timeout': suiteTimeout, + 'dynamic config': test.totalTimeout, + }) + currentTimeout = timeout output.debug(`Test Timeout: ${timeout}s`) timeout *= 1000 @@ -85,6 +103,11 @@ module.exports = function () { event.dispatcher.on(event.step.before, step => { if (typeof timeout !== 'number') return + if (!store.timeouts) { + debug('step', step.toCode().trim(), 'timeout disabled') + return + } + if (timeout < 0) { debug('Previous steps timed out, setting timeout to 0.01s') step.setTimeout(0.01, TIMEOUT_ORDER.testOrSuite) @@ -95,6 +118,11 @@ module.exports = function () { }) event.dispatcher.on(event.step.finished, step => { + if (!store.timeouts) { + debug('step', step.toCode().trim(), 'timeout disabled') + return + } + if (typeof timeout === 'number' && !Number.isNaN(timeout)) timeout -= step.duration if (typeof timeout === 'number' && timeout <= 0 && recorder.isRunning()) { From dd09f1848407f4f72f5d5c63cae289662a3a86e3 Mon Sep 17 00:00:00 2001 From: DavertMik Date: Tue, 14 Jan 2025 03:08:11 +0200 Subject: [PATCH 3/3] fixed global timeouts for BeforeAfterSuite --- lib/listener/globalTimeout.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/listener/globalTimeout.js b/lib/listener/globalTimeout.js index fe5511864..6bb7dd1fe 100644 --- a/lib/listener/globalTimeout.js +++ b/lib/listener/globalTimeout.js @@ -22,9 +22,11 @@ module.exports = function () { // add separate configs to them? event.dispatcher.on(event.hook.started, hook => { if (hook instanceof BeforeSuiteHook) { + timeout = null suiteTimeout = [] } if (hook instanceof AfterSuiteHook) { + timeout = null suiteTimeout = [] } })