Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e9e330057 |
No files matched your search
+9
-10
@@ -65,7 +65,7 @@ function renderWalletList() {
|
|||||||
const pageClosed = new AbortController();
|
const pageClosed = new AbortController();
|
||||||
window.addEventListener("pagehide", () => pageClosed.abort());
|
window.addEventListener("pagehide", () => pageClosed.abort());
|
||||||
|
|
||||||
// While a refresh runs, a request through ctx is not dropped. The request sets
|
// A refresh asked for while another runs is not dropped. The request sets
|
||||||
// refreshAgain, and one more refresh runs once the running one ends. Several
|
// refreshAgain, and one more refresh runs once the running one ends. Several
|
||||||
// requests in that time lead to one more refresh, not several. An import asks
|
// requests in that time lead to one more refresh, not several. An import asks
|
||||||
// for a refresh after its address scan. A refresh already running does not
|
// for a refresh after its address scan. A refresh already running does not
|
||||||
@@ -142,11 +142,13 @@ async function doRefreshAndRender() {
|
|||||||
});
|
});
|
||||||
renderWalletList();
|
renderWalletList();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// No caller waits for this function, so it must never reject. An
|
// Every call site fires this and walks away — the boot below, the ten
|
||||||
// unhandled rejection reports nothing. The save inside it reports its
|
// second interval, eight views through ctx, and the end of this
|
||||||
// own failure through onSaveFailure() (see src/shared/state.js); what
|
// function for one more refresh — so it must never reject: an
|
||||||
// is left here is a failed network round trip, which the next tick
|
// unhandled rejection is not a report of anything. The save
|
||||||
// retries.
|
// inside it reports its own failure through onSaveFailure() (see
|
||||||
|
// src/shared/state.js); what is left here is a failed network round
|
||||||
|
// trip, which the next tick retries.
|
||||||
log.errorf("popup: background refresh failed:", e);
|
log.errorf("popup: background refresh failed:", e);
|
||||||
} finally {
|
} finally {
|
||||||
refreshInFlight = false;
|
refreshInFlight = false;
|
||||||
@@ -167,10 +169,7 @@ function startRefresh() {
|
|||||||
if (!$("view-state-recovery").classList.contains("hidden")) return;
|
if (!$("view-state-recovery").classList.contains("hidden")) return;
|
||||||
doRefreshAndRender();
|
doRefreshAndRender();
|
||||||
if (refreshTimer === null) {
|
if (refreshTimer === null) {
|
||||||
// A tick that finds a refresh running is dropped.
|
refreshTimer = setInterval(doRefreshAndRender, 10000);
|
||||||
refreshTimer = setInterval(() => {
|
|
||||||
if (!refreshInFlight) return doRefreshAndRender();
|
|
||||||
}, 10000);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
// While a refresh runs, a request through ctx is not dropped. One more refresh
|
// A refresh asked for while another runs is not dropped. One more refresh runs
|
||||||
// runs once the running one ends, however many were asked for in that time
|
// once the running one ends, however many were asked for in that time
|
||||||
// (https://git.eeqj.de/sneak/AutistMask/issues/581). A tick of the ten-second
|
// (https://git.eeqj.de/sneak/AutistMask/issues/581). Each test boots the real
|
||||||
// timer that finds a refresh running is dropped. Each test boots the real popup
|
// popup over a stored profile and holds the ten-second refresh open. The
|
||||||
// over a stored profile and holds the ten-second refresh open. `readChain()`
|
// balance stand-in writes what the chain holds onto every address, as the real
|
||||||
// sets each address's balance from `CHAIN`, as the real `refreshBalances()`
|
// refreshBalances() does.
|
||||||
// sets it from the node.
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
bootPopup,
|
bootPopup,
|
||||||
@@ -101,16 +100,6 @@ async function importPhrase(page) {
|
|||||||
await page.click("btn-add-wallet-confirm");
|
await page.click("btn-add-wallet-confirm");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Imports the private key `key` on AddWallet.
|
|
||||||
async function importKey(page, key) {
|
|
||||||
await page.click("btn-add-wallet-bottom");
|
|
||||||
await page.click("tab-privkey");
|
|
||||||
page.node("import-private-key").value = key;
|
|
||||||
page.node("add-wallet-password").value = PASSWORD;
|
|
||||||
page.node("add-wallet-password-confirm").value = PASSWORD;
|
|
||||||
await page.click("btn-add-wallet-confirm");
|
|
||||||
}
|
|
||||||
|
|
||||||
test("addresses an import finds while a refresh runs show their balances once one more refresh returns", async () => {
|
test("addresses an import finds while a refresh runs show their balances once one more refresh returns", async () => {
|
||||||
const { page } = await boot();
|
const { page } = await boot();
|
||||||
const refresh = await holdRefresh(page);
|
const refresh = await holdRefresh(page);
|
||||||
@@ -132,8 +121,8 @@ test("several refreshes asked for while one runs lead to exactly one more", asyn
|
|||||||
const refresh = await holdRefresh(page);
|
const refresh = await holdRefresh(page);
|
||||||
const calls = refreshBalances.mock.calls.length;
|
const calls = refreshBalances.mock.calls.length;
|
||||||
|
|
||||||
await importKey(page, "0x" + "11".repeat(32));
|
await page.tick();
|
||||||
await importKey(page, "0x" + "22".repeat(32));
|
await page.tick();
|
||||||
await importPhrase(page);
|
await importPhrase(page);
|
||||||
expect(refreshBalances).toHaveBeenCalledTimes(calls);
|
expect(refreshBalances).toHaveBeenCalledTimes(calls);
|
||||||
|
|
||||||
@@ -142,16 +131,3 @@ test("several refreshes asked for while one runs lead to exactly one more", asyn
|
|||||||
|
|
||||||
expect(refreshBalances).toHaveBeenCalledTimes(calls + 1);
|
expect(refreshBalances).toHaveBeenCalledTimes(calls + 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("a tick of the ten-second timer while a refresh runs queues no other refresh", async () => {
|
|
||||||
const { page, refreshBalances } = await boot();
|
|
||||||
const refresh = await holdRefresh(page);
|
|
||||||
const calls = refreshBalances.mock.calls.length;
|
|
||||||
|
|
||||||
await page.tick();
|
|
||||||
|
|
||||||
await refresh.finish();
|
|
||||||
await page.settle();
|
|
||||||
|
|
||||||
expect(refreshBalances).toHaveBeenCalledTimes(calls);
|
|
||||||
});
|
|
||||||
Reference in new issue
Block a user