a8bd44a6ec
There was some nasty global-ish variable reference updating happening when the native module 'initializes' after its require with `require('pg').native` This fixes the issue by making sure both `require('pg')` and `require('pg').native` each initialize their own context in isolation and no weird global-ish references are used & subsequently stomped on.
44 lines
1.0 KiB
JavaScript
44 lines
1.0 KiB
JavaScript
var util = require('util');
|
|
var EventEmitter = require('events').EventEmitter;
|
|
|
|
var libDir = __dirname + '/../../../lib';
|
|
var defaults = require(libDir + '/defaults');
|
|
var poolsFactory = require(libDir + '/pool');
|
|
var poolId = 0;
|
|
|
|
require(__dirname + '/../../test-helper');
|
|
|
|
var FakeClient = function() {
|
|
EventEmitter.call(this);
|
|
}
|
|
|
|
util.inherits(FakeClient, EventEmitter);
|
|
|
|
FakeClient.prototype.connect = function(cb) {
|
|
process.nextTick(cb);
|
|
}
|
|
|
|
FakeClient.prototype.end = function() {
|
|
this.endCalled = true;
|
|
}
|
|
|
|
defaults.poolIdleTimeout = 10;
|
|
defaults.reapIntervalMillis = 10;
|
|
|
|
var pools = poolsFactory(FakeClient)
|
|
|
|
test('client times out from idle', function() {
|
|
var p = pools.getOrCreate(poolId++);
|
|
p.connect(function(err, client, done) {
|
|
done();
|
|
});
|
|
process.nextTick(function() {
|
|
assert.equal(p.availableObjectsCount(), 1);
|
|
assert.equal(p.getPoolSize(), 1);
|
|
setTimeout(function() {
|
|
assert.equal(p.availableObjectsCount(), 0);
|
|
assert.equal(p.getPoolSize(), 0);
|
|
}, 50);
|
|
});
|
|
});
|