Fix test timeouts caused by Quick Copy initialization

When an export translator is selected for Quick Copy, Quick Copy
initialization triggers translator initialization a few seconds after
startup, because the translator code needs to be available synchronously
for drag/drop. A Quick Copy test was changing the setting to BibTeX,
which was resulting in random timeouts after subsequent resetDB() calls
due to slow translator loading. This change skips initialization in test
mode. This might actually fix a lot of timeouts on Travis in the second
half of the tests...

This also resets the Quick Copy pref in those tests so that it's left at
the default, though really we should automatically reset all prefs after
all test groups and in resetDB().
This commit is contained in:
Dan Stillman 2016-11-22 20:02:13 -05:00
parent 935d48013b
commit 84bb61ab7b
3 changed files with 17 additions and 8 deletions

View file

@ -38,6 +38,10 @@ Zotero.QuickCopy = new function() {
// Load code for selected export translator ahead of time
// (in the background, because it requires translator initialization)
_initTimeoutID = setTimeout(() => {
// Avoid random translator initialization during tests, which can result in timeouts,
// if an export format is selected
if (Zotero.test) return;
_initTimeoutID = null;
_initPromise = _loadOutputFormat().then(() => _initPromise = null);
}, 5000);

View file

@ -43,11 +43,6 @@ Zotero.Translators = new function() {
* available (e.g., in updateBundledFiles()), to avoid unnecesary file reads
*/
this.reinit = Zotero.Promise.coroutine(function* (options = {}) {
// Travis debugging
Zotero.Debug.init(true);
Zotero.debug(new Error().stack);
Zotero.Debug.init();
// Wait until bundled files have been updated, except when this is called by the schema update
// code itself
if (!options.fromSchemaUpdate) {

View file

@ -1,6 +1,16 @@
describe("Zotero.QuickCopy", function() {
var quickCopyPref = Zotero.Prefs.get("export.quickCopy.setting");
quickCopyPref = JSON.stringify(Zotero.QuickCopy.unserializeSetting(quickCopyPref));
var quickCopyPref;
var prefName = "export.quickCopy.setting";
before(function () {
Zotero.Prefs.clear(prefName);
quickCopyPref = Zotero.Prefs.get(prefName);
quickCopyPref = JSON.stringify(Zotero.QuickCopy.unserializeSetting(quickCopyPref));
});
afterEach(function () {
Zotero.Prefs.clear(prefName);
});
// TODO: These should set site-specific prefs and test the actual response against it,
// but that will need to wait for 5.0. For now, just make sure they don't fail.
@ -44,7 +54,7 @@ describe("Zotero.QuickCopy", function() {
var translatorID = '9cb70025-a888-4a29-a210-93ec52da40d4'; // BibTeX
var format = 'export=' + translatorID;
Zotero.Prefs.set('export.quickCopy.setting', format);
Zotero.Prefs.set(prefName, format);
// Translator code for selected format is loaded automatically, so wait for it
var translator = Zotero.Translators.get(translatorID);
while (!translator.code) {