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:
Brian C 2021-07-27 12:23:30 -05:00 committed by GitHub
parent 0da7882f45
commit 779803fbce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 7 deletions

View File

@ -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()
})

View File

@ -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)
}

View File

@ -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())

View File

@ -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',