From 754886438392480239a30892496ca623d5f72adb Mon Sep 17 00:00:00 2001 From: seaona Date: Thu, 22 Aug 2024 15:23:47 +0200 Subject: [PATCH 1/8] checking race condition point --- .circleci/config.yml | 5 ----- test/e2e/vault-decryption-chrome.spec.js | 3 ++- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9f9d3aacfbbf..74311b887514 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -239,11 +239,6 @@ workflows: - prep-build-test-mmi - get-changed-files-with-git-diff - test-e2e-chrome-vault-decryption: - filters: - branches: - only: - - develop - - /^Version-v(\d+)[.](\d+)[.](\d+)/ requires: - prep-build - test-storybook: diff --git a/test/e2e/vault-decryption-chrome.spec.js b/test/e2e/vault-decryption-chrome.spec.js index a04e25f176de..2638518941ea 100644 --- a/test/e2e/vault-decryption-chrome.spec.js +++ b/test/e2e/vault-decryption-chrome.spec.js @@ -38,7 +38,6 @@ async function getExtensionStorageFilePath(driver) { const logFiles = fs .readdirSync(extensionStoragePath) .filter((filename) => filename.endsWith('.log')); - // Use the first of the `.log` files found return path.resolve(extensionStoragePath, logFiles[0]); } @@ -121,6 +120,8 @@ describe('Vault Decryptor Page', function () { // fill the input field with storage recovered from filesystem await driver.clickElement('[name="vault-source"]'); const inputField = await driver.findElement('#fileinput'); + + await driver.delay(5000); inputField.press(await getExtensionStorageFilePath(driver)); // fill in the password await driver.fill('#passwordinput', WALLET_PASSWORD); From a2dc87b3fa5414510ea9ae1ab9ee77d593c23653 Mon Sep 17 00:00:00 2001 From: seaona Date: Thu, 22 Aug 2024 15:59:31 +0200 Subject: [PATCH 2/8] add retry logic and log --- test/e2e/vault-decryption-chrome.spec.js | 34 ++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/test/e2e/vault-decryption-chrome.spec.js b/test/e2e/vault-decryption-chrome.spec.js index 2638518941ea..bab0c4c2bfe1 100644 --- a/test/e2e/vault-decryption-chrome.spec.js +++ b/test/e2e/vault-decryption-chrome.spec.js @@ -38,6 +38,7 @@ async function getExtensionStorageFilePath(driver) { const logFiles = fs .readdirSync(extensionStoragePath) .filter((filename) => filename.endsWith('.log')); + // Use the first of the `.log` files found return path.resolve(extensionStoragePath, logFiles[0]); } @@ -72,6 +73,21 @@ async function closePopoverIfPresent(driver) { await driver.clickElementSafe(nftAutodetection); } +/** + * Logs the size of a file. + * + * @param {string} filePath - The path to the file to be read. + * @returns {Promise} + */ +async function logFileSize(filePath) { + try { + const stats = await fs.promises.stat(filePath); + console.log(`File Size =========================: ${stats.size} bytes`); + } catch (err) { + console.error(`Error reading file from disk: ${err}`); + } +} + /** * Obtain the SRP from the settings * @@ -121,8 +137,22 @@ describe('Vault Decryptor Page', function () { await driver.clickElement('[name="vault-source"]'); const inputField = await driver.findElement('#fileinput'); - await driver.delay(5000); - inputField.press(await getExtensionStorageFilePath(driver)); + const filePath = await getExtensionStorageFilePath(driver); + + // Log the file size for debugging purposes + await logFileSize(filePath); + await inputField.press(filePath); + + const fileLoaded = await driver.isElementPresent({ + tag: 'span', + text: '❌ Can not read vault from file', + }); + + // Retry-logic if file upload fails + if (!fileLoaded) { + await inputField.press(filePath); + } + // fill in the password await driver.fill('#passwordinput', WALLET_PASSWORD); // decrypt From aeba87099e81e1015585bee2f2a5e986658242d5 Mon Sep 17 00:00:00 2001 From: seaona Date: Thu, 22 Aug 2024 16:17:55 +0200 Subject: [PATCH 3/8] move back config --- .circleci/config.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 74311b887514..9f9d3aacfbbf 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -239,6 +239,11 @@ workflows: - prep-build-test-mmi - get-changed-files-with-git-diff - test-e2e-chrome-vault-decryption: + filters: + branches: + only: + - develop + - /^Version-v(\d+)[.](\d+)[.](\d+)/ requires: - prep-build - test-storybook: From 17af06351a6f492338dd865f0b08ba44beaa7fe3 Mon Sep 17 00:00:00 2001 From: seaona <54408225+seaona@users.noreply.github.com> Date: Fri, 23 Aug 2024 13:47:38 +0200 Subject: [PATCH 4/8] Update test/e2e/vault-decryption-chrome.spec.js --- test/e2e/vault-decryption-chrome.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/vault-decryption-chrome.spec.js b/test/e2e/vault-decryption-chrome.spec.js index bab0c4c2bfe1..697eb6e4a2f0 100644 --- a/test/e2e/vault-decryption-chrome.spec.js +++ b/test/e2e/vault-decryption-chrome.spec.js @@ -143,7 +143,7 @@ describe('Vault Decryptor Page', function () { await logFileSize(filePath); await inputField.press(filePath); - const fileLoaded = await driver.isElementPresent({ + const isFileLoadedError = await driver.isElementPresent({ tag: 'span', text: '❌ Can not read vault from file', }); From 5621c967dcb3a3cdb6f384df6075bf2e62acda82 Mon Sep 17 00:00:00 2001 From: seaona <54408225+seaona@users.noreply.github.com> Date: Fri, 23 Aug 2024 13:47:44 +0200 Subject: [PATCH 5/8] Update test/e2e/vault-decryption-chrome.spec.js --- test/e2e/vault-decryption-chrome.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/vault-decryption-chrome.spec.js b/test/e2e/vault-decryption-chrome.spec.js index 697eb6e4a2f0..d0f67d80ce73 100644 --- a/test/e2e/vault-decryption-chrome.spec.js +++ b/test/e2e/vault-decryption-chrome.spec.js @@ -149,7 +149,7 @@ describe('Vault Decryptor Page', function () { }); // Retry-logic if file upload fails - if (!fileLoaded) { + if (isFileLoadedError) { await inputField.press(filePath); } From ffae80d3daf6d09d5747c68ad180c5fd144287d8 Mon Sep 17 00:00:00 2001 From: seaona Date: Mon, 26 Aug 2024 11:06:35 +0200 Subject: [PATCH 6/8] retry file size before upload --- test/e2e/vault-decryption-chrome.spec.js | 58 ++++++++++++------------ 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/test/e2e/vault-decryption-chrome.spec.js b/test/e2e/vault-decryption-chrome.spec.js index d0f67d80ce73..0f3935195681 100644 --- a/test/e2e/vault-decryption-chrome.spec.js +++ b/test/e2e/vault-decryption-chrome.spec.js @@ -39,10 +39,21 @@ async function getExtensionStorageFilePath(driver) { .readdirSync(extensionStoragePath) .filter((filename) => filename.endsWith('.log')); - // Use the first of the `.log` files found return path.resolve(extensionStoragePath, logFiles[0]); } +/** + * Gets the size of a file in bytes. + * + * @param {string} filePath - The path to the file. + * @returns {Promise} A promise that resolves to the size of the file in bytes. + */ +async function getFileSize(filePath) { + const stats = await fs.promises.stat(filePath); + console.log(`File Size =========================: ${stats.size} bytes`); + return stats.size; +} + /** * Closes the announcements popover if present * @@ -73,21 +84,6 @@ async function closePopoverIfPresent(driver) { await driver.clickElementSafe(nftAutodetection); } -/** - * Logs the size of a file. - * - * @param {string} filePath - The path to the file to be read. - * @returns {Promise} - */ -async function logFileSize(filePath) { - try { - const stats = await fs.promises.stat(filePath); - console.log(`File Size =========================: ${stats.size} bytes`); - } catch (err) { - console.error(`Error reading file from disk: ${err}`); - } -} - /** * Obtain the SRP from the settings * @@ -139,20 +135,26 @@ describe('Vault Decryptor Page', function () { const filePath = await getExtensionStorageFilePath(driver); - // Log the file size for debugging purposes - await logFileSize(filePath); - await inputField.press(filePath); - - const isFileLoadedError = await driver.isElementPresent({ - tag: 'span', - text: '❌ Can not read vault from file', - }); - - // Retry-logic if file upload fails - if (isFileLoadedError) { - await inputField.press(filePath); + // Retry-logic to ensure the file is ready before uploading it + // to mitigate flakiness when Chrome hasn't finished writing + const MAX_RETRIES = 3; + const MIN_FILE_SIZE = 1000000; // bytes + + for (let attempt = 0; attempt < MAX_RETRIES; attempt++) { + const fileSize = await getFileSize(filePath); + if (fileSize > MIN_FILE_SIZE) { + break; + } else { + console.log(`File size is too small (${fileSize} bytes)`); + if (attempt < MAX_RETRIES - 1) { + console.log(`Waiting for 2 seconds before retrying...`); + await driver.delay(2000); + } + } } + await inputField.press(filePath); + // fill in the password await driver.fill('#passwordinput', WALLET_PASSWORD); // decrypt From 6558951a6db6d96f2b9d21025f902bdddbe76743 Mon Sep 17 00:00:00 2001 From: seaona Date: Mon, 26 Aug 2024 11:11:17 +0200 Subject: [PATCH 7/8] add back comment --- test/e2e/vault-decryption-chrome.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/e2e/vault-decryption-chrome.spec.js b/test/e2e/vault-decryption-chrome.spec.js index 0f3935195681..2a105b190424 100644 --- a/test/e2e/vault-decryption-chrome.spec.js +++ b/test/e2e/vault-decryption-chrome.spec.js @@ -39,6 +39,7 @@ async function getExtensionStorageFilePath(driver) { .readdirSync(extensionStoragePath) .filter((filename) => filename.endsWith('.log')); + // Use the first of the `.log` files found return path.resolve(extensionStoragePath, logFiles[0]); } From 7f9762f2cf8dc9f83a8518910f1a4699562bbbd8 Mon Sep 17 00:00:00 2001 From: seaona Date: Mon, 26 Aug 2024 11:11:39 +0200 Subject: [PATCH 8/8] fix lint --- test/e2e/vault-decryption-chrome.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/vault-decryption-chrome.spec.js b/test/e2e/vault-decryption-chrome.spec.js index 2a105b190424..25f79a3e10af 100644 --- a/test/e2e/vault-decryption-chrome.spec.js +++ b/test/e2e/vault-decryption-chrome.spec.js @@ -39,7 +39,7 @@ async function getExtensionStorageFilePath(driver) { .readdirSync(extensionStoragePath) .filter((filename) => filename.endsWith('.log')); - // Use the first of the `.log` files found + // Use the first of the `.log` files found return path.resolve(extensionStoragePath, logFiles[0]); }