Avoid race conditions in conflict resolution tests

This commit is contained in:
Dan Stillman 2018-04-07 17:03:34 -04:00
parent b4244f8a25
commit ac4abf0ebb

View file

@ -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) {