зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1028887 - Cause tests to fail when autoclosing Sqlite.jsm. r=Yoric
This commit is contained in:
Родитель
6e38f19f36
Коммит
4980b5bc66
|
@ -42,6 +42,13 @@ let connectionCounters = new Map();
|
|||
*/
|
||||
let isClosed = false;
|
||||
|
||||
this.Debugging = {
|
||||
// Tests should fail if a connection auto closes. The exception is
|
||||
// when finalization itself is tested, in which case this flag
|
||||
// should be set to false.
|
||||
failTestsOnAutoClose: true
|
||||
};
|
||||
|
||||
// Displays a script error message
|
||||
function logScriptError(message) {
|
||||
let consoleMessage = Cc["@mozilla.org/scripterror;1"].
|
||||
|
@ -51,8 +58,12 @@ function logScriptError(message) {
|
|||
Ci.nsIScriptError.errorFlag, "component javascript");
|
||||
Services.console.logMessage(consoleMessage);
|
||||
|
||||
// Always dump errors, in case the Console Service isn't listening anymore
|
||||
dump("*** " + message + "\n");
|
||||
// This `Promise.reject` will cause tests to fail. The debugging
|
||||
// flag can be used to suppress this for tests that explicitly
|
||||
// test auto closes.
|
||||
if (Debugging.failTestsOnAutoClose) {
|
||||
Promise.reject(new Error(message));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,6 +33,12 @@ function sleep(ms) {
|
|||
return deferred.promise;
|
||||
}
|
||||
|
||||
// When testing finalization, use this to tell Sqlite.jsm to not throw
|
||||
// an uncatchable `Promise.reject`
|
||||
function failTestsOnAutoClose(enabled) {
|
||||
Cu.getGlobalForObject(Sqlite).Debugging.failTestsOnAutoClose = enabled;
|
||||
}
|
||||
|
||||
function getConnection(dbName, extraOptions={}) {
|
||||
let path = dbName + ".sqlite";
|
||||
let options = {path: path};
|
||||
|
@ -911,6 +917,7 @@ add_task(function* test_readOnly_clone() {
|
|||
* Test finalization
|
||||
*/
|
||||
add_task(function* test_closed_by_witness() {
|
||||
failTestsOnAutoClose(false);
|
||||
let c = yield getDummyDatabase("closed_by_witness");
|
||||
|
||||
Services.obs.notifyObservers(null, "sqlite-finalization-witness",
|
||||
|
@ -920,9 +927,11 @@ add_task(function* test_closed_by_witness() {
|
|||
c._witness.forget();
|
||||
yield c._connectionData._deferredClose.promise;
|
||||
do_check_false(c._connectionData._open);
|
||||
failTestsOnAutoClose(true);
|
||||
});
|
||||
|
||||
add_task(function* test_warning_message_on_finalization() {
|
||||
failTestsOnAutoClose(false);
|
||||
let c = yield getDummyDatabase("warning_message_on_finalization");
|
||||
let connectionIdentifier = c._connectionData._connectionIdentifier;
|
||||
let deferred = Promise.defer();
|
||||
|
@ -946,9 +955,11 @@ add_task(function* test_warning_message_on_finalization() {
|
|||
|
||||
yield deferred.promise;
|
||||
Services.console.unregisterListener(listener);
|
||||
failTestsOnAutoClose(true);
|
||||
});
|
||||
|
||||
add_task(function* test_error_message_on_unknown_finalization() {
|
||||
failTestsOnAutoClose(false);
|
||||
let deferred = Promise.defer();
|
||||
|
||||
let listener = {
|
||||
|
@ -965,6 +976,7 @@ add_task(function* test_error_message_on_unknown_finalization() {
|
|||
|
||||
yield deferred.promise;
|
||||
Services.console.unregisterListener(listener);
|
||||
failTestsOnAutoClose(true);
|
||||
});
|
||||
|
||||
add_task(function* test_forget_witness_on_close() {
|
||||
|
@ -985,6 +997,7 @@ add_task(function* test_forget_witness_on_close() {
|
|||
});
|
||||
|
||||
add_task(function* test_close_database_on_gc() {
|
||||
failTestsOnAutoClose(false);
|
||||
let deferred = Promise.defer();
|
||||
|
||||
for (let i = 0; i < 100; ++i) {
|
||||
|
@ -1003,4 +1016,5 @@ add_task(function* test_close_database_on_gc() {
|
|||
|
||||
Components.utils.forceGC();
|
||||
yield deferred.promise;
|
||||
failTestsOnAutoClose(true);
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче