Bug 1809884 - Bust cache when fetching changes in inspect() r=gbeckley

Differential Revision: https://phabricator.services.mozilla.com/D166678
This commit is contained in:
Mathieu Leplatre 2023-01-25 12:36:34 +00:00
parent 198a1b6ad4
commit 03bc251411
2 changed files with 23 additions and 1 deletions

View file

@ -499,10 +499,14 @@ function remoteSettingsFunction() {
* known remote settings collections.
*/
remoteSettings.inspect = async () => {
// Make sure we fetch the latest server info, use a random cache bust value.
const randomCacheBust = 99990000 + Math.floor(Math.random() * 9999);
const {
changes,
currentEtag: serverTimestamp,
} = await lazy.Utils.fetchLatestChanges(lazy.Utils.SERVER_URL);
} = await lazy.Utils.fetchLatestChanges(lazy.Utils.SERVER_URL, {
expected: randomCacheBust,
});
const collections = await Promise.all(
changes.map(async change => {

View file

@ -731,6 +731,24 @@ add_task(async function test_inspect_method() {
});
add_task(clear_state);
add_task(async function test_inspect_method_uses_a_random_cache_bust() {
const backup = Utils.fetchLatestChanges;
const cacheBusts = [];
Utils.fetchLatestChanges = (url, options) => {
cacheBusts.push(options.expected);
return { changes: [] };
};
await RemoteSettings.inspect();
await RemoteSettings.inspect();
await RemoteSettings.inspect();
notEqual(cacheBusts[0], cacheBusts[1]);
notEqual(cacheBusts[1], cacheBusts[2]);
notEqual(cacheBusts[0], cacheBusts[2]);
Utils.fetchLatestChanges = backup;
});
add_task(async function test_clearAll_method() {
// Make sure we have some local data.
await client.maybeSync(2000);