Bug 1098965 - test_close_database_on_gc should use one Promise per database connection. r=Yoric
authorAlexander J. Vincent <ajvincent@gmail.com>
Fri, 21 Nov 2014 06:13:00 +0100
changeset 218283 7c95c7d31d45d1a9b061d81d7380f58f78f9e495
parent 218282 bd3c2c6072a41eef9847c126f300420fa806fd04
child 218284 68c805b2b5e366ea5a596ee7dfb3809f991e9fa1
push id27926
push usercbook@mozilla.com
push dateWed, 03 Dec 2014 12:39:10 +0000
treeherdermozilla-central@a9fc46355661 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs1098965
milestone37.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 1098965 - test_close_database_on_gc should use one Promise per database connection. r=Yoric
toolkit/modules/tests/xpcshell/test_sqlite.js
--- a/toolkit/modules/tests/xpcshell/test_sqlite.js
+++ b/toolkit/modules/tests/xpcshell/test_sqlite.js
@@ -3,16 +3,17 @@
 
 "use strict";
 
 const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
 do_get_profile();
 
 Cu.import("resource://gre/modules/Promise.jsm");
+Cu.import("resource://gre/modules/PromiseUtils.jsm");
 Cu.import("resource://gre/modules/osfile.jsm");
 Cu.import("resource://gre/modules/FileUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/Sqlite.jsm");
 Cu.import("resource://gre/modules/Task.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 // To spin the event loop in test.
@@ -1036,28 +1037,33 @@ add_task(function* test_forget_witness_o
 
   yield c.close();
   // After close, witness should have forgotten the connection
   do_check_true(forgetCalled);
 });
 
 add_task(function* test_close_database_on_gc() {
   failTestsOnAutoClose(false);
-  let deferred = Promise.defer();
+  let finalPromise;
 
-  for (let i = 0; i < 100; ++i) {
-    let c = yield getDummyDatabase("gc_" + i);
-    c._connectionData._deferredClose.promise.then(deferred.resolve);
+  {
+    let collectedPromises = [];
+    for (let i = 0; i < 100; ++i) {
+      let deferred = PromiseUtils.defer();
+      let c = yield getDummyDatabase("gc_" + i);
+      c._connectionData._deferredClose.promise.then(deferred.resolve);
+      collectedPromises.push(deferred.promise);
+    }
+    finalPromise = Promise.all(collectedPromises);
   }
 
   // Call getDummyDatabase once more to clear any remaining
   // references. This is needed at the moment, otherwise
   // garbage-collection takes place after the shutdown barrier and the
   // test will timeout. Once that is fixed, we can remove this line
-  // and be fine as long as at least one connection is
-  // garbage-collected.
+  // and be fine as long as the connections are garbage-collected.
   let last = yield getDummyDatabase("gc_last");
   yield last.close();
 
   Components.utils.forceGC();
-  yield deferred.promise;
+  yield finalPromise;
   failTestsOnAutoClose(true);
 });