Permalink
Browse files

db, feat: add test case of trans result.

  • Loading branch information...
xicilion committed May 15, 2018
1 parent 2de4206 commit 2722598b8b7a1bdb365ead29c42b9cb554416c78
Showing with 8 additions and 4 deletions.
  1. +8 −4 test/db_test.js
View
@@ -191,7 +191,7 @@ describe("db", () => {
it("begin/rollback", () => {
conn.begin();
conn.execute("update test set t2='test101.1' where t1=101");
conn.execute("update test set t2='test101.2' where t1=101");
conn.rollback();
var rs = conn.execute("select * from test where t1=101");
@@ -200,32 +200,36 @@ describe("db", () => {
describe("trans()", () => {
it("auto commit", () => {
conn.trans(function () {
var res = conn.trans(function () {
assert.equal(this, conn);
this.execute("update test set t2='test101.2' where t1=101");
});
assert.equal(res, true);
var rs = conn.execute("select * from test where t1=101");
assert.equal(rs[0].t2, "test101.2");
});
it("auto commit with fiber", () => {
conn.trans(function () {
var res = conn.trans(function () {
assert.equal(this, conn);
coroutine.parallel(() => {
this.execute("update test set t2='test101.2.1' where t1=101");
});
});
assert.equal(res, true);
var rs = conn.execute("select * from test where t1=101");
assert.equal(rs[0].t2, "test101.2.1");
});
it("auto rollback", () => {
conn.trans(function () {
var res = conn.trans(function () {
this.execute("update test set t2='test101.3' where t1=101");
return false;
});
assert.equal(res, false);
var rs = conn.execute("select * from test where t1=101");
assert.equal(rs[0].t2, "test101.2.1");

0 comments on commit 2722598

Please sign in to comment.