mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 05:11:16 +00:00
Bug 1718083 - Load dump if newer than local data r=robwu
Differential Revision: https://phabricator.services.mozilla.com/D141955
This commit is contained in:
parent
e0e7fe2c04
commit
1e8942f6d1
@ -345,7 +345,7 @@ class RemoteSettingsClient extends EventEmitter {
|
||||
* @param {Object} options.filters Filter the results (default: `{}`).
|
||||
* @param {String} options.order The order to apply (eg. `"-last_modified"`).
|
||||
* @param {boolean} options.dumpFallback Fallback to dump data if read of local DB fails (default: `true`).
|
||||
* @param {boolean} options.loadDumpIfNewer Use dump data if it is newer than local data (default: `false`).
|
||||
* @param {boolean} options.loadDumpIfNewer Use dump data if it is newer than local data (default: `true`).
|
||||
* @param {boolean} options.syncIfEmpty Synchronize from server if local data is empty (default: `true`).
|
||||
* @param {boolean} options.verifySignature Verify the signature of the local data (default: `false`).
|
||||
* @return {Promise}
|
||||
@ -355,7 +355,7 @@ class RemoteSettingsClient extends EventEmitter {
|
||||
filters = {},
|
||||
order = "", // not sorted by default.
|
||||
dumpFallback = true,
|
||||
loadDumpIfNewer = false, // TODO bug 1718083: should default to true.
|
||||
loadDumpIfNewer = true,
|
||||
syncIfEmpty = true,
|
||||
} = options;
|
||||
let { verifySignature = false } = options;
|
||||
|
@ -65,30 +65,31 @@ add_task(async function test_load_from_dump_when_offline() {
|
||||
});
|
||||
add_task(clear_state);
|
||||
|
||||
add_task(async function test_skip_dump_after_empty_import() {
|
||||
add_task(async function test_optional_skip_dump_after_empty_import() {
|
||||
// clear_state should have wiped the database.
|
||||
const before = await client.get({ syncIfEmpty: false });
|
||||
equal(before.length, 0, "collection empty after clearing");
|
||||
|
||||
// Verify that the dump is not imported again by client.get()
|
||||
// when the database is initialized with an empty dump.
|
||||
// when the database is initialized with an empty dump
|
||||
// with `loadDumpIfNewer` disabled.
|
||||
await importData([]); // <-- Empty set of records.
|
||||
|
||||
const after = await client.get();
|
||||
const after = await client.get({ loadDumpIfNewer: false });
|
||||
equal(after.length, 0, "collection still empty due to import");
|
||||
equal(await client.getLastModified(), 0, "Empty dump has no timestamp");
|
||||
});
|
||||
add_task(clear_state);
|
||||
|
||||
add_task(async function test_skip_dump_after_non_empty_import() {
|
||||
add_task(async function test_optional_skip_dump_after_non_empty_import() {
|
||||
await importData([{ last_modified: 1234, id: "dummy" }]);
|
||||
|
||||
const after = await client.get();
|
||||
const after = await client.get({ loadDumpIfNewer: false });
|
||||
equal(after.length, 1, "Imported dummy data");
|
||||
equal(await client.getLastModified(), 1234, "Expected timestamp of import");
|
||||
|
||||
await importData([]);
|
||||
const after2 = await client.get();
|
||||
const after2 = await client.get({ loadDumpIfNewer: false });
|
||||
equal(after2.length, 0, "Previous data wiped on duplicate import");
|
||||
equal(await client.getLastModified(), 0, "Timestamp of empty collection");
|
||||
});
|
||||
@ -97,7 +98,7 @@ add_task(clear_state);
|
||||
add_task(async function test_load_dump_after_empty_import() {
|
||||
await importData([]); // <-- Empty set of records, i.e. last_modified = 0.
|
||||
|
||||
const after = await client.get({ loadDumpIfNewer: true });
|
||||
const after = await client.get();
|
||||
equal(after.length, DUMP_RECORDS.length, "Imported dump");
|
||||
equal(await client.getLastModified(), DUMP_LAST_MODIFIED, "dump's timestamp");
|
||||
});
|
||||
@ -110,7 +111,7 @@ add_task(async function test_load_dump_after_non_empty_import() {
|
||||
|
||||
await importData([{ last_modified: 1234, id: "dummy" }]);
|
||||
|
||||
const after = await client.get({ loadDumpIfNewer: true });
|
||||
const after = await client.get();
|
||||
equal(after.length, DUMP_RECORDS.length, "Imported dump");
|
||||
equal(await client.getLastModified(), DUMP_LAST_MODIFIED, "dump's timestamp");
|
||||
});
|
||||
@ -124,7 +125,7 @@ add_task(async function test_load_dump_after_import_from_broken_distro() {
|
||||
// No last_modified time.
|
||||
await importData([{ id: "dummy" }]);
|
||||
|
||||
const after = await client.get({ loadDumpIfNewer: true });
|
||||
const after = await client.get();
|
||||
equal(after.length, DUMP_RECORDS.length, "Imported dump");
|
||||
equal(await client.getLastModified(), DUMP_LAST_MODIFIED, "dump's timestamp");
|
||||
});
|
||||
@ -133,7 +134,7 @@ add_task(clear_state);
|
||||
add_task(async function test_skip_dump_if_same_last_modified() {
|
||||
await importData([{ last_modified: DUMP_LAST_MODIFIED, id: "dummy" }]);
|
||||
|
||||
const after = await client.get({ loadDumpIfNewer: true });
|
||||
const after = await client.get();
|
||||
equal(after.length, 1, "Not importing dump when time matches");
|
||||
equal(await client.getLastModified(), DUMP_LAST_MODIFIED, "Same timestamp");
|
||||
});
|
||||
|
@ -143,7 +143,6 @@ class SearchEngineSelector {
|
||||
try {
|
||||
result = await this._remoteConfig.get({
|
||||
order: "id",
|
||||
loadDumpIfNewer: true,
|
||||
});
|
||||
} catch (ex) {
|
||||
logConsole.error(ex);
|
||||
|
@ -1008,7 +1008,7 @@ const ExtensionBlocklistMLBF = {
|
||||
this._stashes = null;
|
||||
return;
|
||||
}
|
||||
let records = await this._client.get({ loadDumpIfNewer: true });
|
||||
let records = await this._client.get();
|
||||
if (isUpdateReplaced()) {
|
||||
return;
|
||||
}
|
||||
|
@ -198,8 +198,10 @@ add_task(
|
||||
for (const record of records) {
|
||||
await client.db.create(record);
|
||||
}
|
||||
await client.db.importChanges({}, 42); // Prevent from loading JSON dump.
|
||||
const list = await client.get({ syncIfEmpty: false });
|
||||
const list = await client.get({
|
||||
loadDumpIfNewer: false,
|
||||
syncIfEmpty: false,
|
||||
});
|
||||
equal(list.length, 4);
|
||||
ok(list.every(e => e.willMatch));
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ const SAMPLE_GFX_RECORD = {
|
||||
feature: "DIRECT3D_9_LAYERS",
|
||||
devices: ["0x0a6c", "geforce"],
|
||||
featureStatus: "BLOCKED_DRIVER_VERSION",
|
||||
last_modified: 1458035931837,
|
||||
last_modified: 9999999999999, // High timestamp to prevent load of dump
|
||||
os: "WINNT 6.1",
|
||||
id: "3f947f16-37c2-4e96-d356-78b26363729b",
|
||||
versionRange: { minVersion: 0, maxVersion: "*" },
|
||||
|
@ -20,7 +20,8 @@ async function createRecords(records) {
|
||||
id: `record-${i}`,
|
||||
...record,
|
||||
}));
|
||||
return client.db.importChanges({}, 42, withId);
|
||||
// Prevent packaged dump to be loaded with high collection timestamp
|
||||
return client.db.importChanges({}, 9999999999999, withId);
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
|
Loading…
Reference in New Issue
Block a user