Skip to content

Commit

Permalink
Add ref/unref noop to native client (#2581)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
brianc committed Jul 27, 2021
1 parent 0da7882 commit 779803f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/pg-cursor/test/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
Expand Down
3 changes: 3 additions & 0 deletions packages/pg/lib/native/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
11 changes: 6 additions & 5 deletions packages/pg/test/integration/client/connection-timeout-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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)
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -39,7 +40,7 @@ Server.prototype.start = function (cb) {
}.bind(this)
)

var port = 54321
port = port + 1

var options = {
host: 'localhost',
Expand Down

0 comments on commit 779803f

Please sign in to comment.