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

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() {
return [instance, false];
});
});
}).tap(function () {
}).finally(function () {
if (internalTransaction) {
// If we created a transaction internally, we should clean it up
return this.transaction.commit();
......
......@@ -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 test = function(times) {
times = times || 0
if (times > 10) {
return true // stop trying
return true;
}
/*without name, trigger ValidationError */
return self.Student.findOrCreate({where:{no:1},defaults:{}})
return self.Student.findOrCreate({
where: {
no: 1
}
})
.timeout(1000)
.catch(Promise.TimeoutError,function(e){
throw new Error(e)
})
.then(function(){
return true
})
.catch(Sequelize.ValidationError,function(err){
return test(times+1)
return test(times+1);
})
}
test()
.then(function(){
done()
})
.catch(function(err){
done(err)
})
return test(0);
})
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!