Bug 1017237 - Ensure that Sqlite's AsyncShutdown phase displays the name of opened databases in case of crash r=Yoric
☠☠ backed out by 9111ae1bddd7 ☠ ☠
authoraarushivij <aarushivij@gmail.com>
Mon, 27 Apr 2020 15:29:31 +0000
changeset 526268 c1a36d34c2cc3b8d42e615a4891335123af48007
parent 526267 d1cdf76164822ead2ad82be4a4090b0f8c88fc80
child 526269 3d4c4017506c030f023c0d74d482a99d9cae5b28
push id114160
push userdteller@mozilla.com
push dateMon, 27 Apr 2020 15:30:28 +0000
treeherderautoland@c1a36d34c2cc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs1017237
milestone77.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1017237 - Ensure that Sqlite's AsyncShutdown phase displays the name of opened databases in case of crash r=Yoric Differential Revision: https://phabricator.services.mozilla.com/D71398
toolkit/modules/Sqlite.jsm
toolkit/modules/tests/xpcshell/test_sqlite_shutdown.js
--- a/toolkit/modules/Sqlite.jsm
+++ b/toolkit/modules/Sqlite.jsm
@@ -1,15 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
-var EXPORTED_SYMBOLS = ["Sqlite"];
+var EXPORTED_SYMBOLS = ["Sqlite", "Barriers"];
 
 // The maximum time to wait before considering a transaction stuck and rejecting
 // it. (Note that the minimum amount of time we wait is 20% less than this, see
 // the `_getTimeoutPromise` method on `ConnectionData` for details).
 const TRANSACTIONS_QUEUE_TIMEOUT_MS = 300000; // 5 minutes
 
 const { XPCOMUtils } = ChromeUtils.import(
   "resource://gre/modules/XPCOMUtils.jsm"
--- a/toolkit/modules/tests/xpcshell/test_sqlite_shutdown.js
+++ b/toolkit/modules/tests/xpcshell/test_sqlite_shutdown.js
@@ -1,15 +1,15 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 do_get_profile();
-
+let SqliteInternals = ChromeUtils.import("resource://gre/modules/Sqlite.jsm");
 ChromeUtils.import("resource://gre/modules/osfile.jsm");
 // OS.File doesn't like to be first imported during shutdown
 const { Sqlite } = ChromeUtils.import("resource://gre/modules/Sqlite.jsm");
 const { AsyncShutdown } = ChromeUtils.import(
   "resource://gre/modules/AsyncShutdown.jsm"
 );
 
 function getConnection(dbName, extraOptions = {}) {
@@ -55,16 +55,17 @@ function sleep(ms) {
   });
 }
 
 //
 // -----------  Don't add a test after this one, as it shuts down Sqlite.jsm
 //
 add_task(async function test_shutdown_clients() {
   info("Ensuring that Sqlite.jsm doesn't shutdown before its clients");
+  let db1 = await getDummyDatabase("opened before shutdown");
 
   let assertions = [];
 
   let sleepStarted = false;
   let sleepComplete = false;
   Sqlite.shutdown.addBlocker(
     "test_sqlite.js shutdown blocker (sleep)",
     async function() {
@@ -90,17 +91,39 @@ add_task(async function test_shutdown_cl
       let db = await getDummyDatabase("opened during shutdown");
       dbOpened = true;
       db.close().then(() => (dbClosed = true)); // Don't wait for this task to complete, Sqlite.jsm must wait automatically
     }
   );
 
   assertions.push({ name: "dbOpened", value: () => dbOpened });
   assertions.push({ name: "dbClosed", value: () => dbClosed });
+  info(
+    "Making sure that the database we opened before shutdown shows up in the blockers"
+  );
+  SqliteInternals.Barriers.connections.wait();
+  let openedDbArray = SqliteInternals.Barriers.connections.state;
+  ok(
+    openedDbArray.length,
+    "There should be at least one database that shows up in the blockers."
+  );
 
+  function check(element) {
+    let dbOpenedName = element.name;
+    if (dbOpenedName.includes("opened before shutdown")) {
+      return true;
+    }
+    return false;
+  }
+  ok(
+    openedDbArray.some(check),
+    "The db 'opened before shutown' is present in the blocker"
+  );
+
+  db1.close();
   info("Now shutdown Sqlite.jsm synchronously");
   Services.prefs.setBoolPref("toolkit.asyncshutdown.testing", true);
   AsyncShutdown.profileBeforeChange._trigger();
   Services.prefs.clearUserPref("toolkit.asyncshutdown.testing");
 
   for (let { name, value } of assertions) {
     info("Checking: " + name);
     Assert.ok(value());