Commit 652f0ba0 authored by Peter Kotwicz's avatar Peter Kotwicz Committed by Commit Bot

[Android WebAPK] Decrease WebAPK-update-check-interval to 1 day

This CL:
- Decreases the WebAPK update check interval to 1 day. This makes
testing less frustrating
- Removes WebappDataStorage.RETRY_UPDATE_DURATION now that it is the
same duration as WebappDataStorage.UPDATE_INTERVAL

BUG=968252

Change-Id: I6db0e489427613f15d69b449efa3b3a2573e3014
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1635860Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Commit-Queue: Peter Kotwicz <pkotwicz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664480}
parent 42ca473d
......@@ -79,16 +79,12 @@ public class WebappDataStorage {
static final String KEY_PENDING_UPDATE_FILE_PATH = "pending_update_file_path";
// Number of milliseconds between checks for whether the WebAPK's Web Manifest has changed.
public static final long UPDATE_INTERVAL = DateUtils.DAY_IN_MILLIS * 3;
public static final long UPDATE_INTERVAL = DateUtils.DAY_IN_MILLIS;
// Number of milliseconds between checks of updates for a WebAPK that is expected to check
// updates less frequently. crbug.com/680128.
public static final long RELAXED_UPDATE_INTERVAL = DateUtils.DAY_IN_MILLIS * 30;
// Number of milliseconds to wait before re-requesting an updated WebAPK from the WebAPK
// server if the previous update attempt failed.
public static final long RETRY_UPDATE_DURATION = DateUtils.DAY_IN_MILLIS;
// The default shell Apk version of WebAPKs.
static final int DEFAULT_SHELL_APK_VERSION = 1;
......@@ -569,11 +565,7 @@ public class WebappDataStorage {
shouldRelaxUpdates() ? RELAXED_UPDATE_INTERVAL : UPDATE_INTERVAL;
long now = sClock.currentTimeMillis();
long sinceLastCheckDurationMs = now - getLastCheckForWebManifestUpdateTimeMs();
if (sinceLastCheckDurationMs >= checkUpdatesInterval) return true;
long sinceLastUpdateRequestDurationMs = now - getLastWebApkUpdateRequestCompletionTimeMs();
return sinceLastUpdateRequestDurationMs >= RETRY_UPDATE_DURATION
&& !didPreviousUpdateSucceed();
return sinceLastCheckDurationMs >= checkUpdatesInterval;
}
protected WebappDataStorage(String webappId) {
......
......@@ -542,7 +542,7 @@ public class WebApkUpdateManagerUnitTest {
public void testMarkUpdateAsSucceededIfUpdateNoLongerNeeded() {
WebappDataStorage storage = getStorage(WEBAPK_PACKAGE_NAME);
storage.updateDidLastWebApkUpdateRequestSucceed(false);
mClockRule.advance(WebappDataStorage.RETRY_UPDATE_DURATION);
mClockRule.advance(WebappDataStorage.UPDATE_INTERVAL);
TestWebApkUpdateManager updateManager =
new TestWebApkUpdateManager(getStorage(WEBAPK_PACKAGE_NAME));
......
......@@ -306,74 +306,42 @@ public class WebappDataStorageTest {
}
/**
* Test that if the WebAPK update failed (e.g. because the WebAPK server is not reachable) that
* the is-update-needed check is retried after less time than if the WebAPK update had
* succeeded. The is-update-needed check is the first step in retrying to update the WebAPK.
* Test that if the relax-update flag is set to true, the is-update-needed check is done after
* the relaxed update interval (instead of the usual delay).
*/
@Test
public void testCheckUpdateMoreFrequentlyIfUpdateFails() {
assertTrue(WebappDataStorage.UPDATE_INTERVAL > WebappDataStorage.RETRY_UPDATE_DURATION);
public void testRelaxedUpdates() {
assertTrue(WebappDataStorage.RELAXED_UPDATE_INTERVAL > WebappDataStorage.UPDATE_INTERVAL);
WebappDataStorage storage = getStorage();
storage.updateTimeOfLastWebApkUpdateRequestCompletion();
storage.updateDidLastWebApkUpdateRequestSucceed(true);
assertFalse(storage.shouldCheckForUpdate());
mClockRule.advance(WebappDataStorage.RETRY_UPDATE_DURATION);
assertFalse(storage.shouldCheckForUpdate());
// Advance all of the time stamps.
storage.updateTimeOfLastCheckForUpdatedWebManifest();
storage.updateTimeOfLastWebApkUpdateRequestCompletion();
storage.updateDidLastWebApkUpdateRequestSucceed(false);
storage.setRelaxedUpdates(true);
mClockRule.advance(WebappDataStorage.UPDATE_INTERVAL);
assertFalse(storage.shouldCheckForUpdate());
mClockRule.advance(WebappDataStorage.RETRY_UPDATE_DURATION);
mClockRule.advance(
WebappDataStorage.RELAXED_UPDATE_INTERVAL - WebappDataStorage.UPDATE_INTERVAL);
assertTrue(storage.shouldCheckForUpdate());
// Verifies that {@link WebappDataStorage#shouldCheckForUpdate()} returns true because the
// previous update failed, no matter whether we want to check update less frequently.
storage.setRelaxedUpdates(true);
storage.updateTimeOfLastCheckForUpdatedWebManifest();
storage.setRelaxedUpdates(false);
mClockRule.advance(WebappDataStorage.UPDATE_INTERVAL);
assertTrue(storage.shouldCheckForUpdate());
}
/**
* Test that if there was no previous WebAPK update attempt that the is-update-needed check is
* done after the usual delay (as opposed to the shorter delay if the previous WebAPK update
* failed.)
* done after the usual delay (instead of the longer relaxed-update delay).
*/
@Test
public void testRegularCheckIntervalIfNoPriorWebApkUpdate() {
assertTrue(WebappDataStorage.UPDATE_INTERVAL > WebappDataStorage.RETRY_UPDATE_DURATION);
WebappDataStorage storage = getStorage();
assertFalse(storage.shouldCheckForUpdate());
mClockRule.advance(WebappDataStorage.RETRY_UPDATE_DURATION);
assertFalse(storage.shouldCheckForUpdate());
mClockRule.advance(
WebappDataStorage.UPDATE_INTERVAL - WebappDataStorage.RETRY_UPDATE_DURATION);
assertTrue(storage.shouldCheckForUpdate());
}
/**
* Test that if there was no previous WebAPK update attempt and the relax-update flag is set to
* true, the is-update-needed check is done after the relaxed update interval (as opposed to the
* usual delay.)
*/
@Test
public void testRelaxedUpdates() {
assertTrue(WebappDataStorage.RELAXED_UPDATE_INTERVAL > WebappDataStorage.UPDATE_INTERVAL);
WebappDataStorage storage = getStorage();
storage.setRelaxedUpdates(true);
mClockRule.advance(WebappDataStorage.UPDATE_INTERVAL);
assertFalse(storage.shouldCheckForUpdate());
mClockRule.advance(
WebappDataStorage.RELAXED_UPDATE_INTERVAL - WebappDataStorage.UPDATE_INTERVAL);
mClockRule.advance(WebappDataStorage.UPDATE_INTERVAL);
assertTrue(storage.shouldCheckForUpdate());
}
......
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