mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Add ref/unref noop to native client (#2581)
* Add ref/unref noop to native client * Use promise.catch in test * Make partition test not flake on old node * Fix test flake on old node
This commit is contained in:
parent
0da7882f45
commit
779803fbce
@ -26,7 +26,7 @@ describe('cursor using promises', function () {
|
||||
|
||||
it('reject with error', function (done) {
|
||||
const cursor = this.pgCursor('select asdfasdf')
|
||||
cursor.read(1).error((err) => {
|
||||
cursor.read(1).catch((err) => {
|
||||
assert(err)
|
||||
done()
|
||||
})
|
||||
|
||||
@ -285,6 +285,9 @@ Client.prototype.cancel = function (query) {
|
||||
}
|
||||
}
|
||||
|
||||
Client.prototype.ref = function () {}
|
||||
Client.prototype.unref = function () {}
|
||||
|
||||
Client.prototype.setTypeParser = function (oid, format, parseFn) {
|
||||
return this._types.setTypeParser(oid, format, parseFn)
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ const options = {
|
||||
database: 'existing',
|
||||
}
|
||||
|
||||
const serverWithConnectionTimeout = (timeout, callback) => {
|
||||
const serverWithConnectionTimeout = (port, timeout, callback) => {
|
||||
const sockets = new Set()
|
||||
|
||||
const server = net.createServer((socket) => {
|
||||
@ -47,11 +47,11 @@ const serverWithConnectionTimeout = (timeout, callback) => {
|
||||
}
|
||||
}
|
||||
|
||||
server.listen(options.port, options.host, () => callback(closeServer))
|
||||
server.listen(port, options.host, () => callback(closeServer))
|
||||
}
|
||||
|
||||
suite.test('successful connection', (done) => {
|
||||
serverWithConnectionTimeout(0, (closeServer) => {
|
||||
serverWithConnectionTimeout(options.port, 0, (closeServer) => {
|
||||
const timeoutId = setTimeout(() => {
|
||||
throw new Error('Client should have connected successfully but it did not.')
|
||||
}, 3000)
|
||||
@ -67,12 +67,13 @@ suite.test('successful connection', (done) => {
|
||||
})
|
||||
|
||||
suite.test('expired connection timeout', (done) => {
|
||||
serverWithConnectionTimeout(options.connectionTimeoutMillis * 2, (closeServer) => {
|
||||
const opts = { ...options, port: 54322 }
|
||||
serverWithConnectionTimeout(opts.port, opts.connectionTimeoutMillis * 2, (closeServer) => {
|
||||
const timeoutId = setTimeout(() => {
|
||||
throw new Error('Client should have emitted an error but it did not.')
|
||||
}, 3000)
|
||||
|
||||
const client = new helper.Client(options)
|
||||
const client = new helper.Client(opts)
|
||||
client
|
||||
.connect()
|
||||
.then(() => client.end())
|
||||
|
||||
@ -11,6 +11,7 @@ var Server = function (response) {
|
||||
this.response = response
|
||||
}
|
||||
|
||||
let port = 54321
|
||||
Server.prototype.start = function (cb) {
|
||||
// this is our fake postgres server
|
||||
// it responds with our specified response immediatley after receiving every buffer
|
||||
@ -39,7 +40,7 @@ Server.prototype.start = function (cb) {
|
||||
}.bind(this)
|
||||
)
|
||||
|
||||
var port = 54321
|
||||
port = port + 1
|
||||
|
||||
var options = {
|
||||
host: 'localhost',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user