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

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() {
options = Utils._.extend({
events: proxyEventKeys,
skipEvents: []
}, options ||  {});
}, options || {});
options.events = Utils._.difference(options.events, options.skipEvents);
......
......@@ -20,7 +20,7 @@ module.exports = (function() {
this.daos = this.daos.filter(function(_dao) {
return _dao.name !== dao.name;
});
delete this.sequelize.models[dao.name];
};
......
......@@ -81,11 +81,11 @@ module.exports = (function() {
return association.source.update(newValues, { where: query });
});
},
increment: function (targetId) {
increment: function (targetId) {
var query = CounterUtil._sourceQuery(targetId);
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) {
......
......@@ -43,7 +43,6 @@
"validator": "^3.34.0"
},
"devDependencies": {
"async": "~0.9.0",
"chai": "^2.1.2",
"chai-as-promised": "^4.3.0",
"chai-datetime": "~1.3.0",
......
......@@ -1793,7 +1793,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), function() {
self.User.belongsToMany(self.Task, { onDelete: 'RESTRICT'});
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(
self.User.create({ id: 67, username: 'foo' }),
self.Task.create({ id: 52, title: 'task' }),
......
......@@ -11,7 +11,6 @@ var chai = require('chai')
, datetime = require('chai-datetime')
, _ = require('lodash')
, moment = require('moment')
, async = require('async')
, current = Support.sequelize;
chai.use(datetime);
......@@ -2348,12 +2347,13 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
if (dialect !== 'sqlite' && current.dialect.supports.transactions) {
it('supports multiple async transactions', function(done) {
it('supports multiple async transactions', function() {
this.timeout(25000);
var self = this;
return Support.prepareTransactionTest(this.sequelize).bind({}).then(function(sequelize) {
var User = sequelize.define('User', { username: Sequelize.STRING });
var testAsync = function(i, done) {
sequelize.transaction().then(function(t) {
var testAsync = function() {
return sequelize.transaction().then(function(t) {
return User.create({
username: 'foo'
}, {
......@@ -2380,14 +2380,19 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
}).then(function(t) {
return t.rollback();
}).nodeify(done);
});
};
User.sync({ force: true }).then(function() {
return User.sync({ force: true }).then(function() {
var tasks = [];
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() {
});
});
it('triggers the error event for the second transactions', function(done) {
it('triggers the error event for the second transactions', function() {
var self = this;
this.sequelize.transaction().then(function(t1) {
self.sequelize.transaction().then(function(t2) {
self
.Model
.create({ name: 'omnom' }, { transaction: t1 })
.success(function(m1) {
self
.Model
.create({ name: 'omnom' }, { transaction: t2 })
.error(function(err) {
t2.rollback().success(function() {
expect(err).to.be.defined;
done();
});
});
setTimeout(function() { t1.commit(); }, 100);
});
return this.sequelize.transaction().then(function(t1) {
return self.sequelize.transaction().then(function(t2) {
return self.Model.create({ name: 'omnom' }, { transaction: t1 }).then(function(m1) {
return Promise.all([
self.Model.create({ name: 'omnom' }, { transaction: t2 }).catch(function(err) {
expect(err).to.be.defined;
return t2.rollback();
}),
Promise.delay(100).then(function() {
return t1.commit();
})
]);
});
});
});
});
......
......@@ -57,7 +57,7 @@ var Support = {
, _sequelize = new Sequelize(sequelize.config.database, null, null, options);
if (callback) {
_sequelize.sync({ force: true }).success(function() { callback(_sequelize); });
_sequelize.sync({ force: true }).then(function() { callback(_sequelize); });
} else {
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!