Commit 11d7305a authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

Fix equal1PercentageMargin function

NOTE: This CL can introduce FLAKINESS, because the number of metadata
call depends on multiple async calls. I'll watch the bots and update
these tests accordingly.

|equal1PercentageMargin| wasn't checking properly the 1% margin, because
it was comparing to |desiredValue| instead of |value|, this was causing
it to always return true. :-(

Change this function to have ceil/floor so it accounts to at least 1
full unit for min and for max values. Changed it to log the values when
it returns false which is helpful for debugging failing tests.

Change |metadataLargeDrive| test to be more lenient for |fromCache|
metadata calls, because calls to cached metadata are cheap we don't have
to be too strict and running locally it flaked ranging from ~40 to < 70.

Fix small typo.

Bug: 899664
Change-Id: I6c6654684a5b341a3ac7378774cb6fe9b7affe4c
Reviewed-on: https://chromium-review.googlesource.com/c/1317223Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605505}
parent 1f169110
...@@ -13,10 +13,19 @@ ...@@ -13,10 +13,19 @@
* @return {boolean} * @return {boolean}
*/ */
function equal1PercentMargin(value, desiredValue) { function equal1PercentMargin(value, desiredValue) {
const minValue = desiredValue * 0.99; // floor and ceil to account to at least +/-1 unit.
const maxValue = desiredValue * 1.01; const minValue = Math.floor(desiredValue * 0.99);
return value === desiredValue || const maxValue = Math.ceil(desiredValue * 1.01);
(minValue <= desiredValue && desiredValue <= maxValue);
const result =
value === desiredValue || (minValue <= value && value <= maxValue);
if (!result) {
console.log(
'min value: ' + minValue + ' got value: ' + value +
' max value: ' + maxValue);
}
return result;
} }
/** /**
...@@ -188,7 +197,8 @@ testcase.metadataDownloads = function() { ...@@ -188,7 +197,8 @@ testcase.metadataDownloads = function() {
// + 8 files in Downloads again. // + 8 files in Downloads again.
// = 21 // = 21
chrome.test.assertEq(21, metadataStats.fullFetch); chrome.test.assertEq(21, metadataStats.fullFetch);
// 8 files and 3 folders in Downloads when expading in the directory tree. // 8 files and 3 folders in Downloads when expanding in the directory
// tree.
chrome.test.assertEq(0, metadataStats.fromCache); chrome.test.assertEq(0, metadataStats.fromCache);
// Cleared 8 files + 3 folders when navigated out of Downloads and // Cleared 8 files + 3 folders when navigated out of Downloads and
// clearing file list. // clearing file list.
...@@ -256,8 +266,8 @@ testcase.metadataLargeDrive = function() { ...@@ -256,8 +266,8 @@ testcase.metadataLargeDrive = function() {
result &= equal1PercentMargin(metadataStats.fullFetch, 103); result &= equal1PercentMargin(metadataStats.fullFetch, 103);
// 50 team drives cached, reading from file list when navigating to // 50 team drives cached, reading from file list when navigating to
// /team_drives, then read cached when expading directory tree. // /team_drives, then read cached when expanding directory tree.
result &= equal1PercentMargin(metadataStats.fromCache, 62); result &= metadataStats.fromCache < 70;
// Cleared 51 folders when navigated out of My Drive and clearing file // Cleared 51 folders when navigated out of My Drive and clearing file
// list. // list.
...@@ -363,7 +373,7 @@ testcase.metadataTeamDrives = function() { ...@@ -363,7 +373,7 @@ testcase.metadataTeamDrives = function() {
// = 152 // = 152
chrome.test.assertEq(152, metadataStats.fullFetch); chrome.test.assertEq(152, metadataStats.fullFetch);
// 50 team drives cached, reading from file list when navigating to // 50 team drives cached, reading from file list when navigating to
// /team_drives, then read cached when expading directory tree. // /team_drives, then read cached when expanding directory tree.
chrome.test.assertEq(50, metadataStats.fromCache); chrome.test.assertEq(50, metadataStats.fromCache);
// Cleared 50 folders + 50 files when navigated out of My Drive and // Cleared 50 folders + 50 files when navigated out of My Drive and
// clearing file list. // clearing file list.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment