commit 8c32210507114722ab23583f99ccfd0e34aad2c4 parent ba9adffa688b923d361dc9dd1db70a0de9aadb58 Author: Dan Stillman <dstillman@zotero.org> Date: Sun, 26 Apr 2015 17:49:25 -0400 Test for nested transaction failures Diffstat:
| M | test/tests/dbTest.js | | | 21 | +++++++++++++++++++++ |
1 file changed, 21 insertions(+), 0 deletions(-)
diff --git 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); + }); }) });