diff --git a/smoke-test/tests/cypress/cypress/plugins/index.js b/smoke-test/tests/cypress/cypress/plugins/index.js index 161e6895aa260..5e3003aa72cd0 100644 --- a/smoke-test/tests/cypress/cypress/plugins/index.js +++ b/smoke-test/tests/cypress/cypress/plugins/index.js @@ -20,6 +20,9 @@ module.exports = (on, config) => { // `on` is used to hook into various events Cypress emits // `config` is the resolved Cypress config + // eslint-disable-next-line global-require + require("./memoryUsageLogger")(on); + // eslint-disable-next-line global-require require("cypress-timestamps/plugin")(on); }; diff --git a/smoke-test/tests/cypress/cypress/plugins/memoryUsageLogger.js b/smoke-test/tests/cypress/cypress/plugins/memoryUsageLogger.js new file mode 100644 index 0000000000000..d3344b9de8952 --- /dev/null +++ b/smoke-test/tests/cypress/cypress/plugins/memoryUsageLogger.js @@ -0,0 +1,36 @@ +/** + * @type {Cypress.PluginConfig} + */ +// eslint-disable-next-line no-unused-vars +module.exports = (on, config) => { + // Add a task to log memory usage to the terminal + on("task", { + logMemoryUsage(browserMemoryUsage) { + const formatBytes = (bytes) => + (bytes / 1024 / 1024 / 1024).toFixed(3) + " GB"; + + if (browserMemoryUsage) { + console.log("=== Browser Tab Memory Usage ==="); + console.log(`Used: ${formatBytes(browserMemoryUsage.usedJSHeapSize)}`); + console.log( + `Total: ${formatBytes(browserMemoryUsage.totalJSHeapSize)}`, + ); + console.log( + `Limit: ${formatBytes(browserMemoryUsage.jsHeapSizeLimit)}`, + ); + } + + const cypressMemoryUsage = process.memoryUsage(); + console.log("=== Cypress Memory Usage ==="); + console.log(`rss: ${formatBytes(cypressMemoryUsage.rss)}`); + console.log(`heapTotal: ${formatBytes(cypressMemoryUsage.heapTotal)}`); + console.log(`heapUsed: ${formatBytes(cypressMemoryUsage.heapUsed)}`); + console.log(`external: ${formatBytes(cypressMemoryUsage.external)}`); + console.log( + `arrayBuffers: ${formatBytes(cypressMemoryUsage.arrayBuffers)}`, + ); + + return null; + }, + }); +}; diff --git a/smoke-test/tests/cypress/cypress/support/e2e.js b/smoke-test/tests/cypress/cypress/support/e2e.js index 8974faf007429..899b402560085 100644 --- a/smoke-test/tests/cypress/cypress/support/e2e.js +++ b/smoke-test/tests/cypress/cypress/support/e2e.js @@ -39,3 +39,15 @@ beforeEach(function () { } } }); + +afterEach(() => { + cy.window().then((win) => { + const browserMemoryUsage = { + usedJSHeapSize: win.performance?.memory?.usedJSHeapSize, + totalJSHeapSize: win.performance?.memory?.totalJSHeapSize, + jsHeapSizeLimit: win.performance?.memory?.jsHeapSizeLimit, + }; + + cy.task("logMemoryUsage", browserMemoryUsage); + }); +}); diff --git a/smoke-test/tests/cypress/integration_test.py b/smoke-test/tests/cypress/integration_test.py index b1cfd147fff66..efe9ba2629379 100644 --- a/smoke-test/tests/cypress/integration_test.py +++ b/smoke-test/tests/cypress/integration_test.py @@ -262,8 +262,9 @@ def test_run_cypress(auth_session): test_spec_arg = f" --spec '{specs_str}' " print("Running Cypress tests with command") - node_options = "--max-old-space-size=6000" - command = f'NO_COLOR=1 NODE_OPTIONS="{node_options}" npx cypress run {record_arg} {test_spec_arg} {tag_arg} --config numTestsKeptInMemory=2' + node_options = "--max-old-space-size=500" + electron_args = 'ELECTRON_EXTRA_LAUNCH_ARGS="--js-flags=\'--max-old-space-size=4096 --disable-dev-shm-usage --disable-gpu --no-sandbox"' + command = f'{electron_args} NO_COLOR=1 NODE_OPTIONS="{node_options}" npx cypress run {record_arg} {test_spec_arg} {tag_arg} --config numTestsKeptInMemory=2' print(command) # Add --headed --spec '**/mutations/mutations.js' (change spec name) # in case you want to see the browser for debugging