From 8c32210507114722ab23583f99ccfd0e34aad2c4 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 26 Apr 2015 17:49:25 -0400 Subject: [PATCH] Test for nested transaction failures --- test/tests/dbTest.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/tests/dbTest.js b/test/tests/dbTest.js index 1fda5a9b69..5581f0ee96 100644 --- a/test/tests/dbTest.js +++ b/test/tests/dbTest.js @@ -82,5 +82,26 @@ describe("Zotero.DB", function() { yield Zotero.DB.queryAsync("DROP TABLE " + tmpTable); }); + + it("should not commit nested transactions", function* () { + var tmpTable = "tmpNoCommitNested"; + yield Zotero.DB.queryAsync("CREATE TABLE " + tmpTable + " (foo INT)"); + try { + yield Zotero.DB.executeTransaction(function* () { + yield Zotero.DB.queryAsync("INSERT INTO " + tmpTable + " VALUES (1)"); + yield Zotero.DB.executeTransaction(function* () { + yield Zotero.DB.queryAsync("INSERT INTO " + tmpTable + " VALUES (2)"); + throw 'Aborting transaction -- ignore'; + }); + }); + } + catch (e) { + if (typeof e != 'string' || !e.startsWith('Aborting transaction')) throw e; + } + var count = yield Zotero.DB.valueQueryAsync("SELECT COUNT(*) FROM " + tmpTable); + assert.equal(count, 0); + + yield Zotero.DB.queryAsync("DROP TABLE " + tmpTable); + }); }) });