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

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() {
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);
};
......@@ -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');
}
if (this.test.$trackRunningQueries) {
this.test.$runningQueries++;
}
return Promise.resolve(
options.transaction ? options.transaction.connection : self.connectionManager.getConnection(options)
).then(function (connection) {
......@@ -739,6 +754,10 @@ module.exports = (function() {
if (options.transaction) return;
return self.connectionManager.releaseConnection(connection);
});
}).finally(function () {
if (self.test.$trackRunningQueries) {
self.test.$runningQueries--;
}
});
};
......
......@@ -20,7 +20,12 @@ before(function() {
});
beforeEach(function() {
this.sequelize.test.trackRunningQueries();
return Support.clearDatabase(this.sequelize);
});
afterEach(function () {
this.sequelize.test.verifyNoRunningQueries();
});
module.exports = Support;
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!