Bug 1319884 - Address FirefoxAdapter feedback from kinto.js#589, r=mgoodwin

Change FirefoxAdapter definitively to require an externally-managed
Sqlite connection in order to function. This connection must be
produced by calling an openConnection() static method, which does the
work of initializing the tables and schema. Passing any other
connection is wrong, but won't be detected at runtime, and might even
work depending on the previous state of the database. Future work
might define a new KintoSqliteConnection type that can only be
produced by this method, so that it's impossible to create an
uninitialized Kinto database.

This change, since it moves Sqlite connections out of the
FirefoxAdapter, also means that the path option is no longer handled
or provided with a default. This means that the previous default,
"kinto.sqlite", is now preserved in a bunch of places all over the
codebase. This is unfortunate, but a migration is outside the scope of
this patch.

MozReview-Commit-ID: BKJqPR3jOTq

--HG--
extra : rebase_source : 91e0027890ac5fd0ba683abddc23e268f672d169
This commit is contained in:
Ethan Glasser-Camp 2016-11-23 14:18:53 -05:00
Родитель 498e56ef81
Коммит b80b66c130
7 изменённых файлов: 173 добавлений и 170 удалений

Просмотреть файл

@ -38,6 +38,11 @@ const PREF_BLOCKLIST_ENFORCE_SIGNING = "services.blocklist.signing.enfor
const INVALID_SIGNATURE = "Invalid content/signature";
// FIXME: this was the default path in earlier versions of
// FirefoxAdapter, so for backwards compatibility we maintain this
// filename, even though it isn't descriptive of who is using it.
this.KINTO_STORAGE_PATH = "kinto.sqlite";
this.FILENAME_ADDONS_JSON = "blocklist-addons.json";
this.FILENAME_GFX_JSON = "blocklist-gfx.json";
this.FILENAME_PLUGINS_JSON = "blocklist-plugins.json";
@ -77,7 +82,7 @@ function fetchRemoteCollection(collection) {
* URL and bucket name. It uses the `FirefoxAdapter` which relies on SQLite to
* persist the local DB.
*/
function kintoClient() {
function kintoClient(connection) {
let base = Services.prefs.getCharPref(PREF_SETTINGS_SERVER);
let bucket = Services.prefs.getCharPref(PREF_BLOCKLIST_BUCKET);
@ -85,6 +90,7 @@ function kintoClient() {
remote: base,
bucket: bucket,
adapter: FirefoxAdapter,
adapterOptions: {sqliteHandle: connection},
};
return new Kinto(config);
@ -145,7 +151,6 @@ class BlocklistClient {
* @return {Promise} which rejects on sync or process failure.
*/
maybeSync(lastModified, serverTime) {
let db = kintoClient();
let opts = {};
let enforceCollectionSigning =
Services.prefs.getBoolPref(PREF_BLOCKLIST_ENFORCE_SIGNING);
@ -158,11 +163,13 @@ class BlocklistClient {
}
}
let collection = db.collection(this.collectionName, opts);
return Task.spawn((function* syncCollection() {
let connection;
try {
yield collection.db.open();
connection = yield FirefoxAdapter.openConnection({path: KINTO_STORAGE_PATH});
let db = kintoClient(connection);
let collection = db.collection(this.collectionName, opts);
let collectionLastModified = yield collection.db.getLastModified();
// If the data is up to date, there's no need to sync. We still need
@ -205,7 +212,7 @@ class BlocklistClient {
// Track last update.
this.updateLastCheck(serverTime);
} finally {
collection.db.close();
yield connection.close();
}
}).bind(this));
}

Просмотреть файл

@ -189,7 +189,9 @@ const currentSchemaVersion = 1;
* Uses Sqlite as a backing store.
*
* Options:
* - path: the filename/path for the Sqlite database. If absent, use SQLITE_PATH.
* - sqliteHandle: a handle to the Sqlite database this adapter will
* use as its backing store. To open such a handle, use the
* static openConnection() method.
*/
class FirefoxAdapter extends Kinto.adapters.BaseAdapter {
constructor(collection, options = {}) {
@ -200,9 +202,11 @@ class FirefoxAdapter extends Kinto.adapters.BaseAdapter {
this._options = options;
}
// We need to be capable of calling this from "outside" the adapter
// so that someone can initialize a connection and pass it to us in
// adapterOptions.
/**
* Initialize a Sqlite connection to be suitable for use with Kinto.
*
* This will be called automatically by open().
*/
static _init(connection) {
return Task.spawn(function* () {
yield connection.executeTransaction(function* doSetup() {
@ -224,30 +228,22 @@ class FirefoxAdapter extends Kinto.adapters.BaseAdapter {
}
_executeStatement(statement, params) {
if (!this._connection) {
throw new Error("The storage adapter is not open");
}
return this._connection.executeCached(statement, params);
}
open() {
const self = this;
return Task.spawn(function* () {
if (!self._connection) {
const path = self._options.path || SQLITE_PATH;
const opts = { path, sharedMemoryCache: false };
self._connection = yield Sqlite.openConnection(opts).then(FirefoxAdapter._init);
}
});
}
close() {
if (this._connection) {
const promise = this._connection.close();
this._connection = null;
return promise;
}
return Promise.resolve();
/**
* Open and initialize a Sqlite connection to a database that Kinto
* can use. When you are done with this connection, close it by
* calling close().
*
* Options:
* - path: The path for the Sqlite database
*
* @returns SqliteConnection
*/
static async openConnection(options) {
const opts = Object.assign({}, { sharedMemoryCache: false }, options);
return await Sqlite.openConnection(opts).then(this._init);
}
clear() {
@ -256,10 +252,6 @@ class FirefoxAdapter extends Kinto.adapters.BaseAdapter {
}
execute(callback, options = { preload: [] }) {
if (!this._connection) {
throw new Error("The storage adapter is not open");
}
let result;
const conn = this._connection;
const collection = this.collection;

Просмотреть файл

@ -14,21 +14,17 @@ let server;
// set up what we need to make storage adapters
const kintoFilename = "kinto.sqlite";
let kintoClient;
function do_get_kinto_collection(collectionName) {
if (!kintoClient) {
let config = {
// Set the remote to be some server that will cause test failure when
// hit since we should never hit the server directly, only via maybeSync()
remote: "https://firefox.settings.services.mozilla.com/v1/",
// Set up the adapter and bucket as normal
adapter: FirefoxAdapter,
bucket: "blocklists"
};
kintoClient = new Kinto(config);
}
return kintoClient.collection(collectionName);
function do_get_kinto_collection(collectionName, sqliteHandle) {
let config = {
// Set the remote to be some server that will cause test failure when
// hit since we should never hit the server directly, only via maybeSync()
remote: "https://firefox.settings.services.mozilla.com/v1/",
// Set up the adapter and bucket as normal
adapter: FirefoxAdapter,
adapterOptions: {sqliteHandle},
bucket: "blocklists"
};
return new Kinto(config).collection(collectionName);
}
// Some simple tests to demonstrate that the logic inside maybeSync works
@ -72,22 +68,22 @@ add_task(function* test_something(){
// Open the collection, verify it's been populated:
// Our test data has a single record; it should be in the local collection
let collection = do_get_kinto_collection("certificates");
yield collection.db.open();
let sqliteHandle = yield FirefoxAdapter.openConnection({path: kintoFilename});
let collection = do_get_kinto_collection("certificates", sqliteHandle);
let list = yield collection.list();
do_check_eq(list.data.length, 1);
yield collection.db.close();
yield sqliteHandle.close();
// Test the db is updated when we call again with a later lastModified value
result = yield OneCRLBlocklistClient.maybeSync(4000, Date.now());
// Open the collection, verify it's been updated:
// Our test data now has two records; both should be in the local collection
collection = do_get_kinto_collection("certificates");
yield collection.db.open();
sqliteHandle = yield FirefoxAdapter.openConnection({path: kintoFilename});
collection = do_get_kinto_collection("certificates", sqliteHandle);
list = yield collection.list();
do_check_eq(list.data.length, 3);
yield collection.db.close();
yield sqliteHandle.close();
// Try to maybeSync with the current lastModified value - no connection
// should be attempted.

Просмотреть файл

@ -14,6 +14,7 @@ const BlocklistClients = Cu.import("resource://services-common/blocklist-clients
const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1",
"nsIBinaryInputStream", "setInputStream");
const kintoFilename = "kinto.sqlite";
const gBlocklistClients = [
{client: BlocklistClients.AddonBlocklistClient, filename: BlocklistClients.FILENAME_ADDONS_JSON, testData: ["i808","i720", "i539"]},
@ -23,20 +24,17 @@ const gBlocklistClients = [
let server;
let kintoClient;
function kintoCollection(collectionName) {
if (!kintoClient) {
const config = {
// Set the remote to be some server that will cause test failure when
// hit since we should never hit the server directly, only via maybeSync()
remote: "https://firefox.settings.services.mozilla.com/v1/",
adapter: FirefoxAdapter,
bucket: "blocklists"
};
kintoClient = new Kinto(config);
}
return kintoClient.collection(collectionName);
function kintoCollection(collectionName, sqliteHandle) {
const config = {
// Set the remote to be some server that will cause test failure when
// hit since we should never hit the server directly, only via maybeSync()
remote: "https://firefox.settings.services.mozilla.com/v1/",
adapter: FirefoxAdapter,
adapterOptions: {sqliteHandle},
bucket: "blocklists"
};
return new Kinto(config).collection(collectionName);
}
function* readJSON(filepath) {
@ -51,12 +49,13 @@ function* clear_state() {
Services.prefs.clearUserPref(client.lastCheckTimePref);
// Clear local DB.
const collection = kintoCollection(client.collectionName);
let sqliteHandle;
try {
yield collection.db.open();
sqliteHandle = yield FirefoxAdapter.openConnection({path: kintoFilename});
const collection = kintoCollection(client.collectionName, sqliteHandle);
yield collection.clear();
} finally {
yield collection.db.close();
yield sqliteHandle.close();
}
}
@ -126,11 +125,11 @@ add_task(function* test_records_obtained_from_server_are_stored_in_db(){
// Open the collection, verify it's been populated:
// Our test data has a single record; it should be in the local collection
let collection = kintoCollection(client.collectionName);
yield collection.db.open();
const sqliteHandle = yield FirefoxAdapter.openConnection({path: kintoFilename});
let collection = kintoCollection(client.collectionName, sqliteHandle);
let list = yield collection.list();
equal(list.data.length, 1);
yield collection.db.close();
yield sqliteHandle.close();
}
});
add_task(clear_state);

Просмотреть файл

@ -16,6 +16,7 @@ const PREF_BLOCKLIST_ONECRL_COLLECTION = "services.blocklist.onecrl.collection";
const PREF_SETTINGS_SERVER = "services.settings.server";
const PREF_SIGNATURE_ROOT = "security.content.signature.root_hash";
const kintoFilename = "kinto.sqlite";
const CERT_DIR = "test_blocklist_signatures/";
const CHAIN_FILES =
@ -61,23 +62,23 @@ function* checkRecordCount(count) {
const collectionName =
Services.prefs.getCharPref(PREF_BLOCKLIST_ONECRL_COLLECTION);
const sqliteHandle = yield FirefoxAdapter.openConnection({path: kintoFilename});
const config = {
remote: base,
bucket: bucket,
adapter: FirefoxAdapter,
adapterOptions: {sqliteHandle},
};
const db = new Kinto(config);
const collection = db.collection(collectionName);
yield collection.db.open();
// Check we have the expected number of records
let records = yield collection.list();
do_check_eq(count, records.data.length);
// Close the collection so the test can exit cleanly
yield collection.db.close();
yield sqliteHandle.close();
}
// Check to ensure maybeSync is called with correct values when a changes

Просмотреть файл

@ -13,35 +13,37 @@ var server;
// set up what we need to make storage adapters
const kintoFilename = "kinto.sqlite";
let kintoClient;
function do_get_kinto_sqliteHandle() {
return FirefoxAdapter.openConnection({path: kintoFilename});
}
function do_get_kinto_collection() {
if (!kintoClient) {
let config = {
remote:`http://localhost:${server.identity.primaryPort}/v1/`,
headers: {Authorization: "Basic " + btoa("user:pass")},
adapter: FirefoxAdapter
};
kintoClient = new Kinto(config);
}
return kintoClient.collection("test_collection");
function do_get_kinto_collection(sqliteHandle, collection="test_collection") {
let config = {
remote:`http://localhost:${server.identity.primaryPort}/v1/`,
headers: {Authorization: "Basic " + btoa("user:pass")},
adapter: FirefoxAdapter,
adapterOptions: {sqliteHandle},
};
return new Kinto(config).collection(collection);
}
function* clear_collection() {
const collection = do_get_kinto_collection();
let sqliteHandle;
try {
yield collection.db.open();
sqliteHandle = yield do_get_kinto_sqliteHandle();
const collection = do_get_kinto_collection(sqliteHandle);
yield collection.clear();
} finally {
yield collection.db.close();
yield sqliteHandle.close();
}
}
// test some operations on a local collection
add_task(function* test_kinto_add_get() {
const collection = do_get_kinto_collection();
let sqliteHandle;
try {
yield collection.db.open();
sqliteHandle = yield do_get_kinto_sqliteHandle();
const collection = do_get_kinto_collection(sqliteHandle);
let newRecord = { foo: "bar" };
// check a record is created
@ -64,7 +66,7 @@ add_task(function* test_kinto_add_get() {
yield collection.create(newRecord);
yield Promise.all(promises);
} finally {
yield collection.db.close();
yield sqliteHandle.close();
}
});
@ -72,12 +74,11 @@ add_task(clear_collection);
// test some operations on multiple connections
add_task(function* test_kinto_add_get() {
const collection1 = do_get_kinto_collection();
const collection2 = kintoClient.collection("test_collection_2");
let sqliteHandle;
try {
yield collection1.db.open();
yield collection2.db.open();
sqliteHandle = yield do_get_kinto_sqliteHandle();
const collection1 = do_get_kinto_collection(sqliteHandle);
const collection2 = do_get_kinto_collection(sqliteHandle, "test_collection_2");
let newRecord = { foo: "bar" };
@ -94,17 +95,17 @@ add_task(function* test_kinto_add_get() {
collection2.create(newRecord)]);
yield Promise.all(promises);
} finally {
yield collection1.db.close();
yield collection2.db.close();
yield sqliteHandle.close();
}
});
add_task(clear_collection);
add_task(function* test_kinto_update() {
const collection = do_get_kinto_collection();
let sqliteHandle;
try {
yield collection.db.open();
sqliteHandle = yield do_get_kinto_sqliteHandle();
const collection = do_get_kinto_collection(sqliteHandle);
const newRecord = { foo: "bar" };
// check a record is created
let createResult = yield collection.create(newRecord);
@ -121,16 +122,17 @@ add_task(function* test_kinto_update() {
// the record
do_check_eq(updateResult.data._status, "created");
} finally {
yield collection.db.close();
yield sqliteHandle.close();
}
});
add_task(clear_collection);
add_task(function* test_kinto_clear() {
const collection = do_get_kinto_collection();
let sqliteHandle;
try {
yield collection.db.open();
sqliteHandle = yield do_get_kinto_sqliteHandle();
const collection = do_get_kinto_collection(sqliteHandle);
// create an expected number of records
const expected = 10;
@ -146,16 +148,17 @@ add_task(function* test_kinto_clear() {
list = yield collection.list();
do_check_eq(list.data.length, 0);
} finally {
yield collection.db.close();
yield sqliteHandle.close();
}
});
add_task(clear_collection);
add_task(function* test_kinto_delete(){
const collection = do_get_kinto_collection();
let sqliteHandle;
try {
yield collection.db.open();
sqliteHandle = yield do_get_kinto_sqliteHandle();
const collection = do_get_kinto_collection(sqliteHandle);
const newRecord = { foo: "bar" };
// check a record is created
let createResult = yield collection.create(newRecord);
@ -173,14 +176,15 @@ add_task(function* test_kinto_delete(){
do_throw("there should not be a result");
} catch (e) { }
} finally {
yield collection.db.close();
yield sqliteHandle.close();
}
});
add_task(function* test_kinto_list(){
const collection = do_get_kinto_collection();
let sqliteHandle;
try {
yield collection.db.open();
sqliteHandle = yield do_get_kinto_sqliteHandle();
const collection = do_get_kinto_collection(sqliteHandle);
const expected = 10;
const created = [];
for (let i = 0; i < expected; i++) {
@ -204,70 +208,74 @@ add_task(function* test_kinto_list(){
do_check_true(found);
}
} finally {
yield collection.db.close();
yield sqliteHandle.close();
}
});
add_task(clear_collection);
add_task(function* test_loadDump_ignores_already_imported_records(){
const collection = do_get_kinto_collection();
let sqliteHandle;
try {
yield collection.db.open();
sqliteHandle = yield do_get_kinto_sqliteHandle();
const collection = do_get_kinto_collection(sqliteHandle);
const record = {id: "41b71c13-17e9-4ee3-9268-6a41abf9730f", title: "foo", last_modified: 1457896541};
yield collection.loadDump([record]);
let impactedRecords = yield collection.loadDump([record]);
do_check_eq(impactedRecords.length, 0);
} finally {
yield collection.db.close();
yield sqliteHandle.close();
}
});
add_task(clear_collection);
add_task(function* test_loadDump_should_overwrite_old_records(){
const collection = do_get_kinto_collection();
let sqliteHandle;
try {
yield collection.db.open();
sqliteHandle = yield do_get_kinto_sqliteHandle();
const collection = do_get_kinto_collection(sqliteHandle);
const record = {id: "41b71c13-17e9-4ee3-9268-6a41abf9730f", title: "foo", last_modified: 1457896541};
yield collection.loadDump([record]);
const updated = Object.assign({}, record, {last_modified: 1457896543});
let impactedRecords = yield collection.loadDump([updated]);
do_check_eq(impactedRecords.length, 1);
} finally {
yield collection.db.close();
yield sqliteHandle.close();
}
});
add_task(clear_collection);
add_task(function* test_loadDump_should_not_overwrite_unsynced_records(){
const collection = do_get_kinto_collection();
let sqliteHandle;
try {
yield collection.db.open();
sqliteHandle = yield do_get_kinto_sqliteHandle();
const collection = do_get_kinto_collection(sqliteHandle);
const recordId = "41b71c13-17e9-4ee3-9268-6a41abf9730f";
yield collection.create({id: recordId, title: "foo"}, {useRecordId: true});
const record = {id: recordId, title: "bar", last_modified: 1457896541};
let impactedRecords = yield collection.loadDump([record]);
do_check_eq(impactedRecords.length, 0);
} finally {
yield collection.db.close();
yield sqliteHandle.close();
}
});
add_task(clear_collection);
add_task(function* test_loadDump_should_not_overwrite_records_without_last_modified(){
const collection = do_get_kinto_collection();
let sqliteHandle;
try {
yield collection.db.open();
sqliteHandle = yield do_get_kinto_sqliteHandle();
const collection = do_get_kinto_collection(sqliteHandle);
const recordId = "41b71c13-17e9-4ee3-9268-6a41abf9730f";
yield collection.create({id: recordId, title: "foo"}, {synced: true});
const record = {id: recordId, title: "bar", last_modified: 1457896541};
let impactedRecords = yield collection.loadDump([record]);
do_check_eq(impactedRecords.length, 0);
} finally {
yield collection.db.close();
yield sqliteHandle.close();
}
});
@ -305,11 +313,12 @@ add_task(function* test_kinto_sync(){
server.registerPathHandler(recordsPath, handleResponse);
// create an empty collection, sync to populate
const collection = do_get_kinto_collection();
let sqliteHandle;
try {
let result;
sqliteHandle = yield do_get_kinto_sqliteHandle();
const collection = do_get_kinto_collection(sqliteHandle);
yield collection.db.open();
result = yield collection.sync();
do_check_true(result.ok);
@ -331,7 +340,7 @@ add_task(function* test_kinto_sync(){
const after = list.data[0].title;
do_check_neq(before, after);
} finally {
yield collection.db.close();
yield sqliteHandle.close();
}
});

Просмотреть файл

@ -7,13 +7,12 @@ Cu.import("resource://services-common/kinto-storage-adapter.js");
// set up what we need to make storage adapters
const kintoFilename = "kinto.sqlite";
let gFirefoxAdapter = null;
function do_get_kinto_connection() {
return FirefoxAdapter.openConnection({path: kintoFilename});
}
function do_get_kinto_adapter() {
if (gFirefoxAdapter == null) {
gFirefoxAdapter = new FirefoxAdapter("test");
}
return gFirefoxAdapter;
function do_get_kinto_adapter(sqliteHandle) {
return new FirefoxAdapter("test", {sqliteHandle});
}
function do_get_kinto_db() {
@ -28,36 +27,34 @@ function cleanup_kinto() {
let kintoDB = do_get_kinto_db();
// clean up the db
kintoDB.remove(false);
// force re-creation of the adapter
gFirefoxAdapter = null;
run_next_test();
});
}
function test_collection_operations() {
add_task(function* test_kinto_clear() {
let adapter = do_get_kinto_adapter();
yield adapter.open();
let sqliteHandle = yield do_get_kinto_connection();
let adapter = do_get_kinto_adapter(sqliteHandle);
yield adapter.clear();
yield adapter.close();
yield sqliteHandle.close();
});
// test creating new records... and getting them again
add_task(function* test_kinto_create_new_get_existing() {
let adapter = do_get_kinto_adapter();
yield adapter.open();
let sqliteHandle = yield do_get_kinto_connection();
let adapter = do_get_kinto_adapter(sqliteHandle);
let record = {id:"test-id", foo:"bar"};
yield adapter.execute((transaction) => transaction.create(record));
let newRecord = yield adapter.get("test-id");
// ensure the record is the same as when it was added
deepEqual(record, newRecord);
yield adapter.close();
yield sqliteHandle.close();
});
// test removing records
add_task(function* test_kinto_can_remove_some_records() {
let adapter = do_get_kinto_adapter();
yield adapter.open();
let sqliteHandle = yield do_get_kinto_connection();
let adapter = do_get_kinto_adapter(sqliteHandle);
// create a second record
let record = {id:"test-id-2", foo:"baz"};
yield adapter.execute((transaction) => transaction.create(record));
@ -71,24 +68,25 @@ function test_collection_operations() {
// ensure the other record still exists
newRecord = yield adapter.get("test-id");
do_check_neq(newRecord, undefined);
yield adapter.close();
yield sqliteHandle.close();
});
// test getting records that don't exist
add_task(function* test_kinto_get_non_existant() {
let adapter = do_get_kinto_adapter();
let sqliteHandle = yield do_get_kinto_connection();
let adapter = do_get_kinto_adapter(sqliteHandle);
yield adapter.open();
// Kinto expects adapters to either:
let newRecord = yield adapter.get("missing-test-id");
// resolve with an undefined record
do_check_eq(newRecord, undefined);
yield adapter.close();
yield sqliteHandle.close();
});
// test updating records... and getting them again
add_task(function* test_kinto_update_get_existing() {
let adapter = do_get_kinto_adapter();
yield adapter.open();
let sqliteHandle = yield do_get_kinto_connection();
let adapter = do_get_kinto_adapter(sqliteHandle);
let originalRecord = {id:"test-id", foo:"bar"};
let updatedRecord = {id:"test-id", foo:"baz"};
yield adapter.clear();
@ -98,26 +96,26 @@ function test_collection_operations() {
let newRecord = yield adapter.get("test-id");
// ensure the record is the same as when it was added
deepEqual(updatedRecord, newRecord);
yield adapter.close();
yield sqliteHandle.close();
});
// test listing records
add_task(function* test_kinto_list() {
let adapter = do_get_kinto_adapter();
yield adapter.open();
let sqliteHandle = yield do_get_kinto_connection();
let adapter = do_get_kinto_adapter(sqliteHandle);
let originalRecord = {id:"test-id-1", foo:"bar"};
let records = yield adapter.list();
do_check_eq(records.length, 1);
yield adapter.execute((transaction) => transaction.create(originalRecord));
records = yield adapter.list();
do_check_eq(records.length, 2);
yield adapter.close();
yield sqliteHandle.close();
});
// test aborting transaction
add_task(function* test_kinto_aborting_transaction() {
let adapter = do_get_kinto_adapter();
yield adapter.open();
let sqliteHandle = yield do_get_kinto_connection();
let adapter = do_get_kinto_adapter(sqliteHandle);
yield adapter.clear();
let record = {id: 1, foo: "bar"};
let error = null;
@ -132,7 +130,7 @@ function test_collection_operations() {
do_check_neq(error, null);
records = yield adapter.list();
do_check_eq(records.length, 0);
yield adapter.close();
yield sqliteHandle.close();
});
// test save and get last modified
@ -140,8 +138,8 @@ function test_collection_operations() {
const initialValue = 0;
const intendedValue = 12345678;
let adapter = do_get_kinto_adapter();
yield adapter.open();
let sqliteHandle = yield do_get_kinto_connection();
let adapter = do_get_kinto_adapter(sqliteHandle);
let lastModified = yield adapter.getLastModified();
do_check_eq(lastModified, initialValue);
let result = yield adapter.saveLastModified(intendedValue);
@ -156,13 +154,13 @@ function test_collection_operations() {
// and should have saved correctly
lastModified = yield adapter.getLastModified();
do_check_eq(lastModified, intendedValue);
yield adapter.close();
yield sqliteHandle.close();
});
// test loadDump(records)
add_task(function* test_kinto_import_records() {
let adapter = do_get_kinto_adapter();
yield adapter.open();
let sqliteHandle = yield do_get_kinto_connection();
let adapter = do_get_kinto_adapter(sqliteHandle);
let record1 = {id: 1, foo: "bar"};
let record2 = {id: 2, foo: "baz"};
let impactedRecords = yield adapter.loadDump([
@ -175,12 +173,12 @@ function test_collection_operations() {
let newRecord2 = yield adapter.get("2");
// ensure the record is the same as when it was added
deepEqual(record2, newRecord2);
yield adapter.close();
yield sqliteHandle.close();
});
add_task(function* test_kinto_import_records_should_override_existing() {
let adapter = do_get_kinto_adapter();
yield adapter.open();
let sqliteHandle = yield do_get_kinto_connection();
let adapter = do_get_kinto_adapter(sqliteHandle);
yield adapter.clear();
records = yield adapter.list();
do_check_eq(records.length, 0);
@ -197,11 +195,12 @@ function test_collection_operations() {
do_check_eq(records.length, 3);
let newRecord1 = yield adapter.get("1");
deepEqual(newRecord1.foo, "baz");
yield adapter.close();
yield sqliteHandle.close();
});
add_task(function* test_import_updates_lastModified() {
let adapter = do_get_kinto_adapter();
let sqliteHandle = yield do_get_kinto_connection();
let adapter = do_get_kinto_adapter(sqliteHandle);
yield adapter.open();
yield adapter.loadDump([
{id: 1, foo: "bar", last_modified: 1457896541},
@ -209,12 +208,12 @@ function test_collection_operations() {
]);
let lastModified = yield adapter.getLastModified();
do_check_eq(lastModified, 1458796542);
yield adapter.close();
yield sqliteHandle.close();
});
add_task(function* test_import_preserves_older_lastModified() {
let adapter = do_get_kinto_adapter();
yield adapter.open();
let sqliteHandle = yield do_get_kinto_connection();
let adapter = do_get_kinto_adapter(sqliteHandle);
yield adapter.saveLastModified(1458796543);
yield adapter.loadDump([
@ -223,7 +222,7 @@ function test_collection_operations() {
]);
let lastModified = yield adapter.getLastModified();
do_check_eq(lastModified, 1458796543);
yield adapter.close();
yield sqliteHandle.close();
});
}