Skip to content

Commit 779803f

Browse files
authored
Add ref/unref noop to native client (brianc#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
1 parent 0da7882 commit 779803f

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

packages/pg-cursor/test/promises.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('cursor using promises', function () {
2626

2727
it('reject with error', function (done) {
2828
const cursor = this.pgCursor('select asdfasdf')
29-
cursor.read(1).error((err) => {
29+
cursor.read(1).catch((err) => {
3030
assert(err)
3131
done()
3232
})

packages/pg/lib/native/client.js

+3
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ Client.prototype.cancel = function (query) {
285285
}
286286
}
287287

288+
Client.prototype.ref = function () {}
289+
Client.prototype.unref = function () {}
290+
288291
Client.prototype.setTypeParser = function (oid, format, parseFn) {
289292
return this._types.setTypeParser(oid, format, parseFn)
290293
}

packages/pg/test/integration/client/connection-timeout-tests.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const options = {
1313
database: 'existing',
1414
}
1515

16-
const serverWithConnectionTimeout = (timeout, callback) => {
16+
const serverWithConnectionTimeout = (port, timeout, callback) => {
1717
const sockets = new Set()
1818

1919
const server = net.createServer((socket) => {
@@ -47,11 +47,11 @@ const serverWithConnectionTimeout = (timeout, callback) => {
4747
}
4848
}
4949

50-
server.listen(options.port, options.host, () => callback(closeServer))
50+
server.listen(port, options.host, () => callback(closeServer))
5151
}
5252

5353
suite.test('successful connection', (done) => {
54-
serverWithConnectionTimeout(0, (closeServer) => {
54+
serverWithConnectionTimeout(options.port, 0, (closeServer) => {
5555
const timeoutId = setTimeout(() => {
5656
throw new Error('Client should have connected successfully but it did not.')
5757
}, 3000)
@@ -67,12 +67,13 @@ suite.test('successful connection', (done) => {
6767
})
6868

6969
suite.test('expired connection timeout', (done) => {
70-
serverWithConnectionTimeout(options.connectionTimeoutMillis * 2, (closeServer) => {
70+
const opts = { ...options, port: 54322 }
71+
serverWithConnectionTimeout(opts.port, opts.connectionTimeoutMillis * 2, (closeServer) => {
7172
const timeoutId = setTimeout(() => {
7273
throw new Error('Client should have emitted an error but it did not.')
7374
}, 3000)
7475

75-
const client = new helper.Client(options)
76+
const client = new helper.Client(opts)
7677
client
7778
.connect()
7879
.then(() => client.end())

packages/pg/test/integration/client/network-partition-tests.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var Server = function (response) {
1111
this.response = response
1212
}
1313

14+
let port = 54321
1415
Server.prototype.start = function (cb) {
1516
// this is our fake postgres server
1617
// it responds with our specified response immediatley after receiving every buffer
@@ -39,7 +40,7 @@ Server.prototype.start = function (cb) {
3940
}.bind(this)
4041
)
4142

42-
var port = 54321
43+
port = port + 1
4344

4445
var options = {
4546
host: 'localhost',

0 commit comments

Comments
 (0)