tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_connection_failsafe_close.js (1241B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 /*
      6 * This file tests edge-cases related to mozStorageService::unregisterConnection
      7 * in the face of failsafe closing at destruction time which results in
      8 * SpinningSynchronousClose being invoked which can "resurrect" the connection
      9 * and result in a second call to unregisterConnection.
     10 *
     11 * See https://bugzilla.mozilla.org/show_bug.cgi?id=1413501 for more context.
     12 */
     13 
     14 add_task(async function test_failsafe_close_of_async_connection() {
     15  // get the db
     16  let db = getOpenedDatabase();
     17 
     18  // do something async
     19  let callbackInvoked = new Promise(resolve => {
     20    db.executeSimpleSQLAsync("CREATE TABLE test (id INTEGER)", {
     21      handleCompletion: resolve,
     22    });
     23  });
     24 
     25  // drop our reference and force a GC so the only live reference is owned by
     26  // the async statement.
     27  db = gDBConn = null;
     28  // (we don't need to cycle collect)
     29  Cu.forceGC();
     30 
     31  // now we need to wait for that callback to have completed.
     32  await callbackInvoked;
     33 
     34  Assert.ok(true, "if we shutdown cleanly and do not crash, then we succeeded");
     35 });