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

Commit 9f8900f5 by Meg Sharkey

fixed tests not exiting -- make pool maxIdleTime small

1 parent 9c1e7348
......@@ -13,24 +13,34 @@ module.exports = (function() {
this.activeQueue = []
this.maxConcurrentQueries = (this.config.maxConcurrentQueries || 50)
this.poolCfg = this.config.pool
var self = this
if (this.poolCfg) {
//the user has requested pooling, so create our connection pool
if (!this.poolCfg.maxConnections) {
this.poolCfg.maxConnections = 10
}
var self = this
this.pool = Pooling.Pool({
name: 'sequelize-mysql',
create: function (done) {
connect(self, done)
connect.call(self, done)
},
destroy: function(client) {
disconnect(null, client)
disconnect.call(self, client)
},
max: self.poolCfg.maxConnections,
idleTimeoutMillis: self.poolCfg.maxIdleTime
})
}
process.on('exit', function () {
//be nice & close our connections on exit
if (self.pool) {
self.pool.drain()
} else if (self.client) {
disconnect(self.client)
}
return
})
}
Utils._.extend(ConnectorManager.prototype, require("../connector-manager").prototype)
......@@ -56,7 +66,7 @@ module.exports = (function() {
if (this.isConnecting || this.pool) {
return
}
connect(self, function(err, client) {
connect.call(self, function(err, client) {
self.client = client
return
})
......@@ -65,12 +75,15 @@ module.exports = (function() {
ConnectorManager.prototype.disconnect = function() {
if (this.client)
disconnect(this, this.client)
disconnect.call(this, this.client)
return
}
// private
var disconnect = function(self, client) {
var disconnect = function(client) {
var self = this
client.end(function() {
var intervalObj = null
var cleanup = function () {
......@@ -92,7 +105,8 @@ module.exports = (function() {
})
}
var connect = function(self, done) {
var connect = function(done) {
var self = this
var client = require("mysql").createClient({
user: self.config.username,
password: self.config.password,
......@@ -171,7 +185,7 @@ module.exports = (function() {
}
ConnectorManager.prototype.__defineGetter__('hasNoConnections', function() {
return (this.queue.length == 0) && (this.activeQueue.length == 0) && this.client._queue && (this.client._queue.length == 0)
return (this.queue.length == 0) && (this.activeQueue.length == 0) && (this.client == null || (this.client._queue && (this.client._queue.length == 0)))
})
ConnectorManager.prototype.__defineGetter__('isConnected', function() {
......@@ -189,3 +203,5 @@ module.exports = (function() {
return ConnectorManager
})()
......@@ -3,13 +3,14 @@ module.exports = {
return parseInt(Math.random() * 999)
},
//make maxIdleTime small so that tests exit promptly
mysql: {
username: "root",
password: null,
database: 'sequelize_test',
host: '127.0.0.1',
port: 3306,
pool: { maxConnections: 5, maxIdleTime: 30000}
pool: { maxConnections: 5, maxIdleTime: 30}
},
sqlite: {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!