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

Commit a1a13bd1 by Ruben Bridgewater

Refactor transaction test to promise style

Refactor a couple promise tests to use promise style

Refactor another schema test

Fix bad characters used

Refactor the last schema tests to use promises

Use sqlite specifics on timezone test

Refactor last model test to use promises and fix sqlite test

Abandon async from tests

Remove async devDependency
1 parent c4cbb3f3
...@@ -203,7 +203,7 @@ module.exports = (function() { ...@@ -203,7 +203,7 @@ module.exports = (function() {
options = Utils._.extend({ options = Utils._.extend({
events: proxyEventKeys, events: proxyEventKeys,
skipEvents: [] skipEvents: []
}, options ||  {}); }, options || {});
options.events = Utils._.difference(options.events, options.skipEvents); options.events = Utils._.difference(options.events, options.skipEvents);
......
...@@ -20,7 +20,7 @@ module.exports = (function() { ...@@ -20,7 +20,7 @@ module.exports = (function() {
this.daos = this.daos.filter(function(_dao) { this.daos = this.daos.filter(function(_dao) {
return _dao.name !== dao.name; return _dao.name !== dao.name;
}); });
delete this.sequelize.models[dao.name]; delete this.sequelize.models[dao.name];
}; };
......
...@@ -81,11 +81,11 @@ module.exports = (function() { ...@@ -81,11 +81,11 @@ module.exports = (function() {
return association.source.update(newValues, { where: query }); return association.source.update(newValues, { where: query });
}); });
}, },
increment: function (targetId) { increment: function (targetId) {
var query = CounterUtil._sourceQuery(targetId); var query = CounterUtil._sourceQuery(targetId);
return association.source.find({ where: query }).then(function (instance) { return association.source.find({ where: query }).then(function (instance) {
return instance.increment(counterCacheInstance.columnName, { by: 1 }); return instance.increment(counterCacheInstance.columnName, { by: 1 });
}); });
}, },
decrement: function (targetId) { decrement: function (targetId) {
......
...@@ -43,7 +43,6 @@ ...@@ -43,7 +43,6 @@
"validator": "^3.34.0" "validator": "^3.34.0"
}, },
"devDependencies": { "devDependencies": {
"async": "~0.9.0",
"chai": "^2.1.2", "chai": "^2.1.2",
"chai-as-promised": "^4.3.0", "chai-as-promised": "^4.3.0",
"chai-datetime": "~1.3.0", "chai-datetime": "~1.3.0",
......
...@@ -1793,7 +1793,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), function() { ...@@ -1793,7 +1793,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), function() {
self.User.belongsToMany(self.Task, { onDelete: 'RESTRICT'}); self.User.belongsToMany(self.Task, { onDelete: 'RESTRICT'});
self.Task.belongsToMany(self.User, { onDelete: 'CASCADE'}); self.Task.belongsToMany(self.User, { onDelete: 'CASCADE'});
return this.sequelize.sync({ force: true, logging: true }).bind({}).then(function() { return this.sequelize.sync({ force: true }).bind({}).then(function() {
return Sequelize.Promise.join( return Sequelize.Promise.join(
self.User.create({ id: 67, username: 'foo' }), self.User.create({ id: 67, username: 'foo' }),
self.Task.create({ id: 52, title: 'task' }), self.Task.create({ id: 52, title: 'task' }),
......
...@@ -11,7 +11,6 @@ var chai = require('chai') ...@@ -11,7 +11,6 @@ var chai = require('chai')
, datetime = require('chai-datetime') , datetime = require('chai-datetime')
, _ = require('lodash') , _ = require('lodash')
, moment = require('moment') , moment = require('moment')
, async = require('async')
, current = Support.sequelize; , current = Support.sequelize;
chai.use(datetime); chai.use(datetime);
...@@ -2348,12 +2347,13 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -2348,12 +2347,13 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
if (dialect !== 'sqlite' && current.dialect.supports.transactions) { if (dialect !== 'sqlite' && current.dialect.supports.transactions) {
it('supports multiple async transactions', function(done) { it('supports multiple async transactions', function() {
this.timeout(25000); this.timeout(25000);
var self = this;
return Support.prepareTransactionTest(this.sequelize).bind({}).then(function(sequelize) { return Support.prepareTransactionTest(this.sequelize).bind({}).then(function(sequelize) {
var User = sequelize.define('User', { username: Sequelize.STRING }); var User = sequelize.define('User', { username: Sequelize.STRING });
var testAsync = function(i, done) { var testAsync = function() {
sequelize.transaction().then(function(t) { return sequelize.transaction().then(function(t) {
return User.create({ return User.create({
username: 'foo' username: 'foo'
}, { }, {
...@@ -2380,14 +2380,19 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -2380,14 +2380,19 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
}).then(function(t) { }).then(function(t) {
return t.rollback(); return t.rollback();
}).nodeify(done); });
}; };
User.sync({ force: true }).then(function() { return User.sync({ force: true }).then(function() {
var tasks = []; var tasks = [];
for (var i = 0; i < 1000; i++) { for (var i = 0; i < 1000; i++) {
tasks.push(testAsync.bind(this, i)); tasks.push(testAsync.bind(this));
} }
async.parallelLimit(tasks, (sequelize.config.pool && sequelize.config.pool.max || 5) - 1, done); // Needs to be one less than 1 else the non transaction query won't ever get a connection return self.sequelize.Promise.resolve(tasks).map(function(entry) {
return entry();
}, {
// Needs to be one less than ??? else the non transaction query won't ever get a connection
concurrency: (sequelize.config.pool && sequelize.config.pool.max || 5) - 1
});
}); });
}); });
}); });
......
...@@ -131,27 +131,22 @@ describe(Support.getTestDialectTeaser('Sequelize#transaction'), function() { ...@@ -131,27 +131,22 @@ describe(Support.getTestDialectTeaser('Sequelize#transaction'), function() {
}); });
}); });
it('triggers the error event for the second transactions', function(done) { it('triggers the error event for the second transactions', function() {
var self = this; var self = this;
this.sequelize.transaction().then(function(t1) { return this.sequelize.transaction().then(function(t1) {
self.sequelize.transaction().then(function(t2) { return self.sequelize.transaction().then(function(t2) {
self return self.Model.create({ name: 'omnom' }, { transaction: t1 }).then(function(m1) {
.Model return Promise.all([
.create({ name: 'omnom' }, { transaction: t1 }) self.Model.create({ name: 'omnom' }, { transaction: t2 }).catch(function(err) {
.success(function(m1) { expect(err).to.be.defined;
self return t2.rollback();
.Model }),
.create({ name: 'omnom' }, { transaction: t2 }) Promise.delay(100).then(function() {
.error(function(err) { return t1.commit();
t2.rollback().success(function() { })
expect(err).to.be.defined; ]);
done(); });
});
});
setTimeout(function() { t1.commit(); }, 100);
});
}); });
}); });
}); });
......
...@@ -57,7 +57,7 @@ var Support = { ...@@ -57,7 +57,7 @@ var Support = {
, _sequelize = new Sequelize(sequelize.config.database, null, null, options); , _sequelize = new Sequelize(sequelize.config.database, null, null, options);
if (callback) { if (callback) {
_sequelize.sync({ force: true }).success(function() { callback(_sequelize); }); _sequelize.sync({ force: true }).then(function() { callback(_sequelize); });
} else { } else {
return _sequelize.sync({ force: true }).return (_sequelize); return _sequelize.sync({ force: true }).return (_sequelize);
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!