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

Commit c26c5f4d by Mick Hansen

feat(test/misc): utils for verifying sequelize has no running/pending queries

1 parent ce2e86b1
Showing with 24 additions and 0 deletions
...@@ -198,6 +198,17 @@ module.exports = (function() { ...@@ -198,6 +198,17 @@ module.exports = (function() {
this.importCache = {}; this.importCache = {};
this.test = {
$trackRunningQueries: false,
$runningQueries: 0,
trackRunningQueries: function() {
this.$trackRunningQueries = true;
},
verifyNoRunningQueries: function() {
if (this.$runningQueries > 0) throw new Error('Expected 0 running queries. '+this.$runningQueries+' queries still running');
}
};
Sequelize.runHooks('afterInit', this); Sequelize.runHooks('afterInit', this);
}; };
...@@ -731,6 +742,10 @@ module.exports = (function() { ...@@ -731,6 +742,10 @@ module.exports = (function() {
return Promise.reject(options.transaction.finished+' has been called on this transaction, you can no longer use it'); return Promise.reject(options.transaction.finished+' has been called on this transaction, you can no longer use it');
} }
if (this.test.$trackRunningQueries) {
this.test.$runningQueries++;
}
return Promise.resolve( return Promise.resolve(
options.transaction ? options.transaction.connection : self.connectionManager.getConnection(options) options.transaction ? options.transaction.connection : self.connectionManager.getConnection(options)
).then(function (connection) { ).then(function (connection) {
...@@ -739,6 +754,10 @@ module.exports = (function() { ...@@ -739,6 +754,10 @@ module.exports = (function() {
if (options.transaction) return; if (options.transaction) return;
return self.connectionManager.releaseConnection(connection); return self.connectionManager.releaseConnection(connection);
}); });
}).finally(function () {
if (self.test.$trackRunningQueries) {
self.test.$runningQueries--;
}
}); });
}; };
......
...@@ -20,7 +20,12 @@ before(function() { ...@@ -20,7 +20,12 @@ before(function() {
}); });
beforeEach(function() { beforeEach(function() {
this.sequelize.test.trackRunningQueries();
return Support.clearDatabase(this.sequelize); return Support.clearDatabase(this.sequelize);
}); });
afterEach(function () {
this.sequelize.test.verifyNoRunningQueries();
});
module.exports = Support; module.exports = Support;
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!