From f05aa7cfa8617fff6c0a8ac44cad90f1ee901586 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Fri, 29 May 2015 08:43:26 -0700 Subject: [PATCH] Fix the failing tests --- test/transaction.promise.test.js | 29 +++++++++++++---------------- test/transaction.test.js | 22 ++++++++++------------ 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/test/transaction.promise.test.js b/test/transaction.promise.test.js index 5a92fe5..0f16927 100644 --- a/test/transaction.promise.test.js +++ b/test/transaction.promise.test.js @@ -7,7 +7,7 @@ require('should'); var db, Post, Review; -describe('transactions', function() { +describe('transactions with promise', function() { before(function(done) { db = getDataSource({collation: 'utf8_general_ci', createDatabase: true}); @@ -155,26 +155,23 @@ describe('transactions', function() { var post = {title: 't3', content: 'c3'}; before(createPostInTx(post, 500)); - it('should report timeout', function(done) { - setTimeout(function() { - Post.find({where: {title: 't3'}}, {transaction: currentTx}, - function(err, posts) { - if (err) return done(err); - posts.length.should.be.eql(1); - done(); - }); - }, 1000); - done(); - }); - it('should invoke the timeout hook', function(done) { currentTx.observe('timeout', function(context, next) { next(); + // It will only proceed upon timeout done(); }); }); - }); -}) -; + it('should rollback the transaction if timeout', function(done) { + Post.find({where: {title: 't3'}}, {transaction: currentTx}, + function(err, posts) { + if (err) return done(err); + posts.length.should.be.eql(0); + done(); + }); + }); + + }); +}); diff --git a/test/transaction.test.js b/test/transaction.test.js index f8996b8..a1667a4 100644 --- a/test/transaction.test.js +++ b/test/transaction.test.js @@ -158,25 +158,23 @@ describe('transactions', function() { var post = {title: 't3', content: 'c3'}; before(createPostInTx(post, 500)); - it('should report timeout', function(done) { - setTimeout(function() { - Post.find({where: {title: 't3'}}, {transaction: currentTx}, - function(err, posts) { - if (err) return done(err); - posts.length.should.be.eql(1); - done(); - }); - }, 1000); - done(); - }); - it('should invoke the timeout hook', function(done) { currentTx.observe('timeout', function(context, next) { next(); + // It will only proceed upon timeout done(); }); }); + it('should rollback the transaction if timeout', function(done) { + Post.find({where: {title: 't3'}}, {transaction: currentTx}, + function(err, posts) { + if (err) return done(err); + posts.length.should.be.eql(0); + done(); + }); + }); + }); });