mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 1376874 - Close blocklist Sqlite connection on shutdown r=mak
MozReview-Commit-ID: LUV9b8U8jGY --HG-- extra : rebase_source : 607f8054ad00387f17d124c87c0b0b12ce3ee2e2
This commit is contained in:
parent
046089eed8
commit
778f047057
@ -245,7 +245,16 @@ class FirefoxAdapter extends Kinto.adapters.BaseAdapter {
|
||||
*/
|
||||
static async openConnection(options) {
|
||||
const opts = Object.assign({}, { sharedMemoryCache: false }, options);
|
||||
return await Sqlite.openConnection(opts).then(this._init);
|
||||
const conn = await Sqlite.openConnection(opts).then(this._init);
|
||||
try {
|
||||
Sqlite.shutdown.addBlocker("Kinto storage adapter connection closing",
|
||||
async () => await conn.close());
|
||||
} catch (e) {
|
||||
// It's too late to block shutdown, just close the connection.
|
||||
await conn.close();
|
||||
throw e;
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
|
||||
clear() {
|
||||
|
@ -258,7 +258,3 @@ add_test(function test_creation_from_empty_db() {
|
||||
cleanup_kinto();
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
function run_test() {
|
||||
run_next_test();
|
||||
}
|
||||
|
24
services/common/tests/unit/test_storage_adapter_shutdown.js
Normal file
24
services/common/tests/unit/test_storage_adapter_shutdown.js
Normal file
@ -0,0 +1,24 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/AsyncShutdown.jsm");
|
||||
|
||||
Cu.import("resource://services-common/kinto-storage-adapter.js");
|
||||
|
||||
|
||||
add_task(async function test_sqlite_shutdown() {
|
||||
const sqliteHandle = await FirefoxAdapter.openConnection({path: "kinto.sqlite"});
|
||||
|
||||
// Shutdown Sqlite.jsm synchronously.
|
||||
Services.prefs.setBoolPref("toolkit.asyncshutdown.testing", true);
|
||||
AsyncShutdown.profileBeforeChange._trigger();
|
||||
Services.prefs.clearUserPref("toolkit.asyncshutdown.testing");
|
||||
|
||||
try {
|
||||
sqliteHandle.execute("SELECT 1;");
|
||||
equal("Should not succeed, connection should be closed.", false);
|
||||
} catch (e) {
|
||||
equal(e.message, "Connection is not open.");
|
||||
}
|
||||
});
|
@ -25,6 +25,8 @@ tags = blocklist
|
||||
tags = blocklist
|
||||
[test_storage_adapter.js]
|
||||
tags = blocklist
|
||||
[test_storage_adapter_shutdown.js]
|
||||
tags = blocklist
|
||||
|
||||
[test_utils_atob.js]
|
||||
[test_utils_convert_string.js]
|
||||
|
Loading…
Reference in New Issue
Block a user