Fix "Can't queue event outside of a transaction"

If a transaction took over 30 seconds and another transaction timed out
waiting for it, the second transaction would reset the notifier queue,
but if the first transaction then tried to queue an event, it would fail
with this error and roll back. (It would be nice to figure out why
transactions are taking over 30 seconds, though.)
This commit is contained in:
Dan Stillman 2018-02-08 02:07:44 -05:00
parent 80cfd609ea
commit 3f6ecc0021
4 changed files with 45 additions and 20 deletions

View file

@ -57,4 +57,25 @@ describe("Zotero.Notifier", function () {
Zotero.Notifier.unregisterObserver(id);
});
});
describe("#queue", function () {
it("should handle notification after DB timeout from another transaction", async function () {
var promise1 = Zotero.DB.executeTransaction(async function () {
var item = createUnsavedDataObject('item');
await item.save();
await Zotero.Promise.delay(2000);
Zotero.Notifier.queue('refresh', 'item', item.id);
}.bind(this));
var promise2 = Zotero.DB.executeTransaction(async function () {
var item = createUnsavedDataObject('item');
await item.save();
}.bind(this), { waitTimeout: 1000 });
await promise1;
assert.isTrue(promise2.isRejected());
});
});
});