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

Commit d86c20ed by Mick Hansen

fix issue where findOrCreate would not properly release transaction on error, closes #2238

1 parent c817fd0b
Showing with 10 additions and 18 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();
......
...@@ -137,36 +137,28 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -137,36 +137,28 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}) })
}) })
it("should release transaction when meeting errors", function(done){ it("should release transaction when meeting errors", function(){
var self = this var self = this
var test = function(times) { var test = function(times) {
times = times || 0
if (times > 10) { if (times > 10) {
return true // stop trying return true;
} }
return self.Student.findOrCreate({
/*without name, trigger ValidationError */ where: {
return self.Student.findOrCreate({where:{no:1},defaults:{}}) no: 1
}
})
.timeout(1000) .timeout(1000)
.catch(Promise.TimeoutError,function(e){ .catch(Promise.TimeoutError,function(e){
throw new Error(e) throw new Error(e)
}) })
.then(function(){
return true
})
.catch(Sequelize.ValidationError,function(err){ .catch(Sequelize.ValidationError,function(err){
return test(times+1) return test(times+1);
}) })
} }
test() return test(0);
.then(function(){
done()
})
.catch(function(err){
done(err)
})
}) })
describe('several concurrent calls', function () { describe('several concurrent calls', function () {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!