Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: flaky test Vault Decryptor Page is able to decrypt the vault us.. due to empty file load #26612

Merged
merged 8 commits into from
Aug 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion test/e2e/vault-decryption-chrome.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ async function getExtensionStorageFilePath(driver) {
return path.resolve(extensionStoragePath, logFiles[0]);
}

/**
* Gets the size of a file in bytes.
*
* @param {string} filePath - The path to the file.
* @returns {Promise<number>} 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
*
Expand Down Expand Up @@ -121,7 +133,29 @@ 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');
inputField.press(await getExtensionStorageFilePath(driver));

const filePath = await getExtensionStorageFilePath(driver);

// 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
Expand Down