|
1 | 1 | 'use strict'
|
2 | 2 | var helper = require('./test-helper')
|
3 | 3 | const pg = helper.pg
|
| 4 | +const native = helper.args.native |
4 | 5 |
|
5 | 6 | const suite = new helper.Suite()
|
6 | 7 | suite.test('connecting to invalid port', (cb) => {
|
@@ -102,14 +103,28 @@ suite.test('connection-level errors cause future queries to fail', (cb) => {
|
102 | 103 |
|
103 | 104 | suite.test('handles socket error during pool.query and destroys it immediately', (cb) => {
|
104 | 105 | const pool = new pg.Pool({ max: 1 })
|
105 |
| - pool.query('SELECT pg_sleep(10)', [], (err) => { |
106 |
| - assert.equal(err.message, 'network issue') |
107 |
| - assert.equal(stream.destroyed, true) |
108 |
| - cb() |
109 |
| - }) |
110 | 106 |
|
111 |
| - const stream = pool._clients[0].connection.stream |
112 |
| - setTimeout(() => { |
113 |
| - stream.emit('error', new Error('network issue')) |
114 |
| - }, 100) |
| 107 | + if (native) { |
| 108 | + pool.query('SELECT pg_sleep(10)', [], (err) => { |
| 109 | + assert.equal(err.message, 'canceling statement due to user request') |
| 110 | + cb() |
| 111 | + }) |
| 112 | + |
| 113 | + setTimeout(() => { |
| 114 | + pool._clients[0].native.cancel((err) => { |
| 115 | + assert.ifError(err) |
| 116 | + }) |
| 117 | + }, 100) |
| 118 | + } else { |
| 119 | + pool.query('SELECT pg_sleep(10)', [], (err) => { |
| 120 | + assert.equal(err.message, 'network issue') |
| 121 | + assert.equal(stream.destroyed, true) |
| 122 | + cb() |
| 123 | + }) |
| 124 | + |
| 125 | + const stream = pool._clients[0].connection.stream |
| 126 | + setTimeout(() => { |
| 127 | + stream.emit('error', new Error('network issue')) |
| 128 | + }, 100) |
| 129 | + } |
115 | 130 | })
|
0 commit comments