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

Commit ca2714e7 by Mick Hansen

deadlocking testcases for #3070

1 parent 3fd1f1f3
...@@ -1125,12 +1125,13 @@ module.exports = (function() { ...@@ -1125,12 +1125,13 @@ module.exports = (function() {
, whereFields , whereFields
, defaultFields; , defaultFields;
queryOptions = queryOptions ? Utils._.clone(queryOptions) : {};
if (!options || !options.where) { if (!options || !options.where) {
throw new Error('Missing where attribute in the options parameter passed to findOrCreate. Please note that the API has changed, and is now options (an object with where and defaults keys), queryOptions (transaction etc.)'); throw new Error('Missing where attribute in the options parameter passed to findOrCreate. Please note that the API has changed, and is now options (an object with where and defaults keys), queryOptions (transaction etc.)');
} }
queryOptions = queryOptions ? Utils._.clone(queryOptions) : {};
if (options.logging) queryOptions.logging = options.logging;
whereFields = Object.keys(options.where); whereFields = Object.keys(options.where);
if (options.defaults) defaultFields = Object.keys(options.defaults); if (options.defaults) defaultFields = Object.keys(options.defaults);
......
...@@ -108,6 +108,89 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -108,6 +108,89 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
}); });
if (current.dialect.name !== 'sequelize') {
it('should not deadlock with no existing entries and no outer transaction', function () {
var User = this.sequelize.define('User', {
email: {
type: DataTypes.STRING,
unique: 'company_user_email'
},
companyId: {
type: DataTypes.INTEGER,
unique: 'company_user_email'
}
});
return User.sync({force: true}).then(function () {
return Promise.map(_.range(50), function (i) {
return User.findOrCreate({
where: {
email: 'unique.email.'+i+'@sequelizejs.com',
companyId: Math.floor(Math.random() * 5)
}
});
});
});
});
it('should not deadlock with existing entries and no outer transaction', function () {
var User = this.sequelize.define('User', {
email: {
type: DataTypes.STRING,
unique: 'company_user_email'
},
companyId: {
type: DataTypes.INTEGER,
unique: 'company_user_email'
}
});
return User.sync({force: true}).then(function () {
return Promise.map(_.range(50), function (i) {
return User.findOrCreate({
where: {
email: 'unique.email.'+i+'@sequelizejs.com',
companyId: 2
}
});
}).then(function () {
return Promise.map(_.range(50), function (i) {
return User.findOrCreate({
where: {
email: 'unique.email.'+i+'@sequelizejs.com',
companyId: 2
}
});
});
});
});
});
it('should not deadlock with concurrency duplicate entries and no outer transaction', function () {
var User = this.sequelize.define('User', {
email: {
type: DataTypes.STRING,
unique: 'company_user_email'
},
companyId: {
type: DataTypes.INTEGER,
unique: 'company_user_email'
}
});
return User.sync({force: true}).then(function () {
return Promise.map(_.range(50), function (i) {
return User.findOrCreate({
where: {
email: 'unique.email.1@sequelizejs.com',
companyId: 2
}
});
});
});
});
}
it('should support special characters in defaults', function () { it('should support special characters in defaults', function () {
var User = this.sequelize.define('user', { var User = this.sequelize.define('user', {
objectId: { objectId: {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!