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

Commit c817fd0b by Mick Hansen

Merge branch 'test/issue_2238' of https://github.com/ryanking8215/sequelize into…

… ryanking8215-test/issue_2238
2 parents 6fccaa8d 95843f45
Showing with 36 additions and 0 deletions
...@@ -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,38 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -133,6 +137,38 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}) })
}) })
it("should release transaction when meeting errors", function(done){
var self = this
var test = function(times) {
times = times || 0
if (times > 10) {
return true // stop trying
}
/*without name, trigger ValidationError */
return self.Student.findOrCreate({where:{no:1},defaults:{}})
.timeout(1000)
.catch(Promise.TimeoutError,function(e){
throw new Error(e)
})
.then(function(){
return true
})
.catch(Sequelize.ValidationError,function(err){
return test(times+1)
})
}
test()
.then(function(){
done()
})
.catch(function(err){
done(err)
})
})
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!