不要怂,就是干,撸起袖子干!

Commit faf948ea by Ruben Bridgewater

Fix transactions not rolling back properly

Fix test to actually check for the rollback happening
1 parent d1662c13
...@@ -1142,18 +1142,18 @@ module.exports = (function() { ...@@ -1142,18 +1142,18 @@ module.exports = (function() {
var result = autoCallback(transaction); var result = autoCallback(transaction);
if (!result || !result.then) return reject(new Error('You need to return a promise chain/thenable to the sequelize.transaction() callback')); if (!result || !result.then) return reject(new Error('You need to return a promise chain/thenable to the sequelize.transaction() callback'));
result.then(function (result) { return result.then(function (result) {
return transaction.commit().then(function () { return transaction.commit().then(function () {
resolve(result); resolve(result);
}); });
}).then(null, function (err) {
transaction.rollback().then(function () {
reject(err);
}, function () {
reject(err);
});
}); });
}).catch(reject); }).catch(function(err) {
transaction.rollback().then(function () {
reject(err);
}, function () {
reject(err);
});
});
}; };
if (ns) { if (ns) {
......
...@@ -45,9 +45,13 @@ describe(Support.getTestDialectTeaser('Transaction'), function() { ...@@ -45,9 +45,13 @@ describe(Support.getTestDialectTeaser('Transaction'), function() {
}); });
}); });
it('supports automatically rolling back with a thrown error', function() { it('supports automatically rolling back with a thrown error', function() {
return expect(this.sequelize.transaction(function() { var t;
return (expect(this.sequelize.transaction(function(transaction) {
t = transaction;
throw new Error('Yolo'); throw new Error('Yolo');
})).to.eventually.be.rejected; })).to.eventually.be.rejected).then(function() {
expect(t.finished).to.be.equal('rollback');
});
}); });
it('supports automatically rolling back with a rejection', function() { it('supports automatically rolling back with a rejection', function() {
return expect(this.sequelize.transaction(function() { return expect(this.sequelize.transaction(function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!