Commit 354eba77 authored by Nicholas Verne's avatar Nicholas Verne Committed by Commit Bot

Crostini: Attempt the upgrade up to 3 times

Upgrading is a long and potentially flaky process. If the flakes are
due to remote repos being unavailable, retrying the upgrade is useful,
since some apt commands in the upgrade can continue where they left off.
This should increase the number of upgrade successes in the wild.

Bug: 1084825
Change-Id: Ib0adf945fb60eb2e682204d949cf7aa7a273d0a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2228590
Commit-Queue: Nicholas Verne <nverne@chromium.org>
Reviewed-by: default avatarDaniel Ng <danielng@google.com>
Cr-Commit-Position: refs/heads/master@{#774970}
parent 2df4bdfe
......@@ -32,6 +32,8 @@ const State = {
SUCCEEDED: 'succeeded',
};
const kMaxUpgradeAttempts = 3;
Polymer({
is: 'crostini-upgrader-app',
......@@ -91,6 +93,12 @@ Polymer({
value: 300,
},
/** @private */
upgradeAttemptCount_: {
type: Number,
value: 0,
},
/**
* Enable the html template to use State.
* @private
......@@ -155,6 +163,10 @@ Polymer({
}),
callbackRouter.onUpgradeFailed.addListener(() => {
assert(this.state_ === State.UPGRADING);
if (this.upgradeAttemptCount_ < kMaxUpgradeAttempts) {
this.precheckThenUpgrade_();
return;
}
if (this.backupCheckboxChecked_) {
this.state_ = State.OFFER_RESTORE;
} else {
......@@ -198,6 +210,13 @@ Polymer({
this.listenerIds_.forEach(id => callbackRouter.removeListener(id));
},
/** @private */
precheckThenUpgrade_() {
this.startPrechecks_(() => {
this.startUpgrade_();
}, () => {});
},
/** @private */
onActionButtonClick_() {
switch (this.state_) {
......@@ -207,16 +226,13 @@ Polymer({
this.closeDialog_();
break;
case State.PRECHECKS_FAILED:
this.startPrechecks_(() => {
this.startUpgrade_();
}, () => {});
this.precheckThenUpgrade_();
break;
case State.PROMPT:
if (this.backupCheckboxChecked_) {
this.startBackup_(/*showFileChooser=*/ false);
} else {
this.startPrechecks_(() => {
this.startUpgrade_();
}, () => {});
this.precheckThenUpgrade_();
}
break;
case State.OFFER_RESTORE:
......@@ -271,6 +287,7 @@ Polymer({
/** @private */
startUpgrade_() {
this.state_ = State.UPGRADING;
this.upgradeAttemptCount_++;
BrowserProxy.getInstance().handler.upgrade();
},
......
......@@ -196,15 +196,18 @@ suite('<crostini-upgrader-app>', () => {
expectEquals(fakeBrowserProxy.handler.getCallCount('upgrade'), 0);
// The UI pauses for 2000 ms before continuing.
await waitMillis(2010).then(flushTasks());
fakeBrowserProxy.page.precheckStatus(
chromeos.crostiniUpgrader.mojom.UpgradePrecheckStatus.OK);
await flushTasks();
expectEquals(fakeBrowserProxy.handler.getCallCount('upgrade'), 1);
expectFalse(getUpgradeProgressBar().hidden);
fakeBrowserProxy.page.onUpgradeProgress(['foo', 'bar']);
fakeBrowserProxy.page.onUpgradeFailed();
await flushTasks();
const kMaxUpgradeAttempts = 3;
for (let i = 0; i < kMaxUpgradeAttempts; i++) {
fakeBrowserProxy.page.precheckStatus(
chromeos.crostiniUpgrader.mojom.UpgradePrecheckStatus.OK);
await flushTasks();
expectEquals(fakeBrowserProxy.handler.getCallCount('upgrade'), i + 1);
expectFalse(getUpgradeProgressBar().hidden);
fakeBrowserProxy.page.onUpgradeProgress(['foo', 'bar']);
fakeBrowserProxy.page.onUpgradeFailed();
await flushTasks();
}
expectEquals(fakeBrowserProxy.handler.getCallCount('restore'), 0);
await clickAction();
......
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