From ac4abf0ebb39f3a6968669a3eb1065f08d65735e Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 7 Apr 2018 17:03:34 -0400 Subject: [PATCH] Avoid race conditions in conflict resolution tests --- test/tests/syncEngineTest.js | 51 ++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/test/tests/syncEngineTest.js b/test/tests/syncEngineTest.js index c954227fc5..770712daa0 100644 --- a/test/tests/syncEngineTest.js +++ b/test/tests/syncEngineTest.js @@ -12,7 +12,7 @@ describe("Zotero.Sync.Data.Engine", function () { var setup = Zotero.Promise.coroutine(function* (options = {}) { server = sinon.fakeServer.create(); - server.autoRespond = true; + server.respondImmediately = true; var background = options.background === undefined ? true : options.background; var stopOnError = options.stopOnError === undefined ? true : options.stopOnError; @@ -2084,7 +2084,7 @@ describe("Zotero.Sync.Data.Engine", function () { } }); - waitForWindow('chrome://zotero/content/merge.xul', function (dialog) { + var crPromise = waitForWindow('chrome://zotero/content/merge.xul', function (dialog) { var doc = dialog.document; var wizard = doc.documentElement; var mergeGroup = wizard.getElementsByTagName('zoteromergegroup')[0]; @@ -2099,6 +2099,7 @@ describe("Zotero.Sync.Data.Engine", function () { wizard.getButton('finish').click(); }) yield engine._startDownload(); + yield crPromise; assert.isFalse(Zotero.Items.exists(itemID1)); assert.isTrue(Zotero.Items.exists(itemID2)); @@ -2312,12 +2313,13 @@ describe("Zotero.Sync.Data.Engine", function () { } }); - waitForWindow('chrome://zotero/content/merge.xul', function (dialog) { + var crPromise = waitForWindow('chrome://zotero/content/merge.xul', function (dialog) { var doc = dialog.document; var wizard = doc.documentElement; wizard.getButton('cancel').click(); }) var e = yield getPromiseError(engine._startDownload()); + yield crPromise assert.isTrue(e instanceof Zotero.Sync.UserCancelledException); // Non-conflicted item should be saved @@ -2406,12 +2408,13 @@ describe("Zotero.Sync.Data.Engine", function () { } }); - waitForWindow('chrome://zotero/content/merge.xul', function (dialog) { + var crPromise = waitForWindow('chrome://zotero/content/merge.xul', function (dialog) { var doc = dialog.document; var wizard = doc.documentElement; wizard.getButton('cancel').click(); }) var e = yield getPromiseError(engine._startDownload()); + yield crPromise; assert.isTrue(e instanceof Zotero.Sync.UserCancelledException); // Conflicted items should still exists @@ -3187,7 +3190,7 @@ describe("Zotero.Sync.Data.Engine", function () { json: responseJSON }); - waitForWindow('chrome://zotero/content/merge.xul', function (dialog) { + var crPromise = waitForWindow('chrome://zotero/content/merge.xul', function (dialog) { var doc = dialog.document; var wizard = doc.documentElement; var mergeGroup = wizard.getElementsByTagName('zoteromergegroup')[0]; @@ -3212,6 +3215,7 @@ describe("Zotero.Sync.Data.Engine", function () { wizard.getButton('finish').click(); }) await engine._downloadObjects('item', objects.map(o => o.key)); + await crPromise; assert.equal(objects[0].getField('title'), values[0].right.title); assert.equal(objects[1].getField('title'), values[1].left.title); @@ -3293,7 +3297,7 @@ describe("Zotero.Sync.Data.Engine", function () { json: responseJSON }); - waitForWindow('chrome://zotero/content/merge.xul', function (dialog) { + var crPromise = waitForWindow('chrome://zotero/content/merge.xul', function (dialog) { var doc = dialog.document; var wizard = doc.documentElement; var mergeGroup = wizard.getElementsByTagName('zoteromergegroup')[0]; @@ -3318,6 +3322,7 @@ describe("Zotero.Sync.Data.Engine", function () { wizard.getButton('finish').click(); }); await engine._downloadObjects('item', objects.map(o => o.key)); + await crPromise; assert.equal(objects[0].getNote(), values[0].right.note); assert.equal(objects[1].getNote(), values[1].left.note); @@ -3408,7 +3413,7 @@ describe("Zotero.Sync.Data.Engine", function () { json: responseJSON }); - waitForWindow('chrome://zotero/content/merge.xul', function (dialog) { + var crPromise = waitForWindow('chrome://zotero/content/merge.xul', function (dialog) { var doc = dialog.document; var wizard = doc.documentElement; var mergeGroup = wizard.getElementsByTagName('zoteromergegroup')[0]; @@ -3442,11 +3447,7 @@ describe("Zotero.Sync.Data.Engine", function () { wizard.getButton('finish').click(); }) await engine._downloadObjects('item', objects.map(o => o.key)); - - Zotero.debug('=-=-=-='); - Zotero.debug(objects[0].toJSON()); - Zotero.debug(objects[1].toJSON()); - Zotero.debug(objects[2].toJSON()); + await crPromise; // First object should match remote assert.equal(objects[0].getField('title'), values[0].right.title); @@ -3534,7 +3535,7 @@ describe("Zotero.Sync.Data.Engine", function () { json: responseJSON }); - waitForWindow('chrome://zotero/content/merge.xul', function (dialog) { + var crPromise = waitForWindow('chrome://zotero/content/merge.xul', function (dialog) { var doc = dialog.document; var wizard = doc.documentElement; var mergeGroup = wizard.getElementsByTagName('zoteromergegroup')[0]; @@ -3567,6 +3568,7 @@ describe("Zotero.Sync.Data.Engine", function () { wizard.getButton('finish').click(); }) await engine._downloadObjects('item', objects.map(o => o.key)); + await crPromise; assert.equal(objects[0].getField('title'), values[0].right.title); assert.equal(objects[0].version, values[0].right.version); @@ -3618,10 +3620,7 @@ describe("Zotero.Sync.Data.Engine", function () { json: responseJSON }); - var windowOpened = false; - waitForWindow('chrome://zotero/content/merge.xul', function (dialog) { - windowOpened = true; - + var crPromise = waitForWindow('chrome://zotero/content/merge.xul', function (dialog) { var doc = dialog.document; var wizard = doc.documentElement; var mergeGroup = wizard.getElementsByTagName('zoteromergegroup')[0]; @@ -3634,7 +3633,7 @@ describe("Zotero.Sync.Data.Engine", function () { wizard.getButton('finish').click(); }) yield engine._downloadObjects('item', [obj.key]); - assert.isTrue(windowOpened); + yield crPromise; obj = objectsClass.getByLibraryAndKey(libraryID, key); assert.isFalse(obj); @@ -3681,10 +3680,7 @@ describe("Zotero.Sync.Data.Engine", function () { json: responseJSON }); - var windowOpened = false; - waitForWindow('chrome://zotero/content/merge.xul', function (dialog) { - windowOpened = true; - + var crPromise = waitForWindow('chrome://zotero/content/merge.xul', function (dialog) { var doc = dialog.document; var wizard = doc.documentElement; var mergeGroup = wizard.getElementsByTagName('zoteromergegroup')[0]; @@ -3697,7 +3693,7 @@ describe("Zotero.Sync.Data.Engine", function () { wizard.getButton('finish').click(); }); yield engine._downloadObjects('item', [obj.key]); - assert.isTrue(windowOpened); + yield crPromise; obj = Zotero.Items.getByLibraryAndKey(libraryID, key); assert.isFalse(obj); @@ -3739,7 +3735,7 @@ describe("Zotero.Sync.Data.Engine", function () { json: responseJSON }); - waitForWindow('chrome://zotero/content/merge.xul', function (dialog) { + var crPromise = waitForWindow('chrome://zotero/content/merge.xul', function (dialog) { var doc = dialog.document; var wizard = doc.documentElement; var mergeGroup = wizard.getElementsByTagName('zoteromergegroup')[0]; @@ -3751,6 +3747,7 @@ describe("Zotero.Sync.Data.Engine", function () { wizard.getButton('finish').click(); }) yield engine._downloadObjects('item', [key]); + yield crPromise; obj = objectsClass.getByLibraryAndKey(libraryID, key); assert.ok(obj); @@ -4151,9 +4148,7 @@ describe("Zotero.Sync.Data.Engine", function () { }); // Apply remote deletions - var shown = false; - waitForWindow('chrome://zotero/content/merge.xul', function (dialog) { - shown = true; + var crPromise = waitForWindow('chrome://zotero/content/merge.xul', function (dialog) { var doc = dialog.document; var wizard = doc.documentElement; var mergeGroup = wizard.getElementsByTagName('zoteromergegroup')[0]; @@ -4173,7 +4168,7 @@ describe("Zotero.Sync.Data.Engine", function () { }); yield engine._fullSync(); - assert.ok(shown); + yield crPromise; // Check objects for (let type of types) {