mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 12:25:53 +00:00
Bug 1227045 - fix intermittent test failures due to the cache file not being consistently saved before test-triggered restarts, r=mak.
This commit is contained in:
parent
1486293294
commit
5bf82e8de0
@ -3090,17 +3090,29 @@ SearchService.prototype = {
|
||||
// Start by clearing the initialized state, so we don't abort early.
|
||||
gInitialized = false;
|
||||
|
||||
// Clear the engines, too, so we don't stick with the stale ones.
|
||||
this._engines = {};
|
||||
this.__sortedEngines = null;
|
||||
this._currentEngine = null;
|
||||
this._defaultEngine = null;
|
||||
this._visibleDefaultEngines = [];
|
||||
this._metaData = {};
|
||||
this._cacheFileJSON = null;
|
||||
|
||||
Task.spawn(function* () {
|
||||
try {
|
||||
if (this._batchTask) {
|
||||
LOG("finalizing batch task");
|
||||
let task = this._batchTask;
|
||||
this._batchTask = null;
|
||||
yield task.finalize();
|
||||
}
|
||||
|
||||
// Clear the engines, too, so we don't stick with the stale ones.
|
||||
this._engines = {};
|
||||
this.__sortedEngines = null;
|
||||
this._currentEngine = null;
|
||||
this._defaultEngine = null;
|
||||
this._visibleDefaultEngines = [];
|
||||
this._metaData = {};
|
||||
this._cacheFileJSON = null;
|
||||
|
||||
// Tests that want to force a synchronous re-initialization need to
|
||||
// be notified when we are done uninitializing.
|
||||
Services.obs.notifyObservers(null, SEARCH_SERVICE_TOPIC,
|
||||
"uninit-complete");
|
||||
|
||||
let cache = {};
|
||||
cache = yield this._asyncReadCacheFile();
|
||||
if (!gInitialized && cache.metaData)
|
||||
|
@ -84,14 +84,13 @@ add_task(function* no_request_if_prefed_off() {
|
||||
add_task(function* should_get_geo_defaults_only_once() {
|
||||
// (Re)initializing the search service should trigger a request,
|
||||
// and set the default engine based on it.
|
||||
let commitPromise = promiseAfterCache();
|
||||
// Due to the previous initialization, we expect the countryCode to already be set.
|
||||
do_check_true(Services.prefs.prefHasUserValue("browser.search.countryCode"));
|
||||
do_check_eq(Services.prefs.getCharPref("browser.search.countryCode"), "FR");
|
||||
yield asyncReInit();
|
||||
checkRequest();
|
||||
do_check_eq(Services.search.currentEngine.name, kTestEngineName);
|
||||
yield commitPromise;
|
||||
yield promiseAfterCache();
|
||||
|
||||
// Verify the metadata was written correctly.
|
||||
let metadata = yield promiseGlobalMetadata();
|
||||
@ -110,20 +109,18 @@ add_task(function* should_get_geo_defaults_only_once() {
|
||||
|
||||
add_task(function* should_request_when_countryCode_not_set() {
|
||||
Services.prefs.clearUserPref("browser.search.countryCode");
|
||||
let commitPromise = promiseAfterCache();
|
||||
yield asyncReInit();
|
||||
checkRequest();
|
||||
yield commitPromise;
|
||||
yield promiseAfterCache();
|
||||
});
|
||||
|
||||
add_task(function* should_recheck_if_interval_expired() {
|
||||
yield forceExpiration();
|
||||
|
||||
let commitPromise = promiseAfterCache();
|
||||
let date = Date.now();
|
||||
yield asyncReInit();
|
||||
checkRequest();
|
||||
yield commitPromise;
|
||||
yield promiseAfterCache();
|
||||
|
||||
// Check that the expiration timestamp has been updated.
|
||||
let metadata = yield promiseGlobalMetadata();
|
||||
@ -146,7 +143,9 @@ add_task(function* should_recheck_when_broken_hash() {
|
||||
yield promiseSaveGlobalMetadata(metadata);
|
||||
|
||||
let commitPromise = promiseAfterCache();
|
||||
let unInitPromise = waitForSearchNotification("uninit-complete");
|
||||
let reInitPromise = asyncReInit();
|
||||
yield unInitPromise;
|
||||
|
||||
// Synchronously check the current default engine, to force a sync init.
|
||||
// The hash is wrong, so we should fallback to the default engine from prefs.
|
||||
@ -161,6 +160,14 @@ add_task(function* should_recheck_when_broken_hash() {
|
||||
// Check that the hash is back to its previous value.
|
||||
metadata = yield promiseGlobalMetadata();
|
||||
do_check_eq(typeof metadata.searchDefaultHash, "string");
|
||||
if (metadata.searchDefaultHash == "broken") {
|
||||
// If the server takes more than 1000ms to return the result,
|
||||
// the commitPromise was resolved by a first save of the cache
|
||||
// that saved the engines, but not the request's results.
|
||||
do_print("waiting for the cache to be saved a second time");
|
||||
yield promiseAfterCache();
|
||||
metadata = yield promiseGlobalMetadata();
|
||||
}
|
||||
do_check_eq(metadata.searchDefaultHash, hash);
|
||||
|
||||
// The current default engine shouldn't change during a session.
|
||||
@ -170,7 +177,9 @@ add_task(function* should_recheck_when_broken_hash() {
|
||||
// without doing yet another request.
|
||||
yield asyncReInit();
|
||||
checkNoRequest();
|
||||
commitPromise = promiseAfterCache();
|
||||
do_check_eq(Services.search.currentEngine.name, kTestEngineName);
|
||||
yield commitPromise;
|
||||
});
|
||||
|
||||
add_task(function* should_remember_cohort_id() {
|
||||
|
@ -67,6 +67,7 @@ add_task(function* sync_init() {
|
||||
do_check_neq(engine, null);
|
||||
|
||||
yield reInitPromise;
|
||||
yield promiseAfterCache();
|
||||
});
|
||||
|
||||
add_task(function* invalid_engine() {
|
||||
@ -79,7 +80,6 @@ add_task(function* invalid_engine() {
|
||||
let url = "data:application/json,{\"interval\": 31536000, \"settings\": {\"searchDefault\": \"hidden\", \"visibleDefaultEngines\": [\"hidden\", \"bogus\"]}}";
|
||||
Services.prefs.getDefaultBranch(BROWSER_SEARCH_PREF).setCharPref(kUrlPref, url);
|
||||
|
||||
let commitPromise = promiseAfterCache();
|
||||
yield asyncReInit();
|
||||
|
||||
let engines = Services.search.getEngines();
|
||||
|
Loading…
Reference in New Issue
Block a user