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

Commit c9e23615 by Mick Hansen

Merge branch 'ryanking8215-test/issue_2238'

2 parents 6fccaa8d d86c20ed
Showing with 29 additions and 1 deletions
...@@ -1141,7 +1141,7 @@ module.exports = (function() { ...@@ -1141,7 +1141,7 @@ module.exports = (function() {
return [instance, false]; return [instance, false];
}); });
}); });
}).tap(function () { }).finally(function () {
if (internalTransaction) { if (internalTransaction) {
// If we created a transaction internally, we should clean it up // If we created a transaction internally, we should clean it up
return this.transaction.commit(); return this.transaction.commit();
......
...@@ -31,6 +31,10 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -31,6 +31,10 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
this.Account = this.sequelize.define('Account', { this.Account = this.sequelize.define('Account', {
accountName: DataTypes.STRING accountName: DataTypes.STRING
}); });
this.Student = this.sequelize.define('Student', {
no: {type:DataTypes.INTEGER,primaryKey:true},
name: {type:DataTypes.STRING,allowNull:false},
})
return this.sequelize.sync({ force: true }); return this.sequelize.sync({ force: true });
}); });
...@@ -133,6 +137,30 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -133,6 +137,30 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}) })
}) })
it("should release transaction when meeting errors", function(){
var self = this
var test = function(times) {
if (times > 10) {
return true;
}
return self.Student.findOrCreate({
where: {
no: 1
}
})
.timeout(1000)
.catch(Promise.TimeoutError,function(e){
throw new Error(e)
})
.catch(Sequelize.ValidationError,function(err){
return test(times+1);
})
}
return test(0);
})
describe('several concurrent calls', function () { describe('several concurrent calls', function () {
it('works with a transaction', function () { it('works with a transaction', function () {
return this.sequelize.transaction().bind(this).then(function (transaction) { return this.sequelize.transaction().bind(this).then(function (transaction) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!