Skip to content

Commit 28ac2a1

Browse files
authored
Add test for how to set search path (#2700)
Also refactor a few tests a bit to slowly clean up some of the old style.
1 parent 3ca5602 commit 28ac2a1

File tree

5 files changed

+51
-62
lines changed

5 files changed

+51
-62
lines changed

Diff for: packages/pg/test/integration/client/type-coercion-tests.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict'
22
var helper = require('./test-helper')
33
var pg = helper.pg
4-
var sink
54
const suite = new helper.Suite()
65

76
var testForTypeCoercion = function (type) {
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,41 @@
11
'use strict'
2-
var helper = require('./test-helper')
2+
const helper = require('../test-helper')
3+
const assert = require('assert')
34

4-
helper.testPoolSize(1)
5+
const suite = new helper.Suite()
56

6-
helper.testPoolSize(2)
7+
const testPoolSize = function (max) {
8+
suite.testAsync(`test ${max} queries executed on a pool rapidly`, () => {
9+
const pool = new helper.pg.Pool({ max: 10 })
710

8-
helper.testPoolSize(40)
11+
let count = 0
912

10-
helper.testPoolSize(200)
13+
return new Promise((resolve) => {
14+
for (var i = 0; i < max; i++) {
15+
pool.connect(function (err, client, release) {
16+
assert(!err)
17+
client.query('SELECT * FROM NOW()')
18+
client.query('select generate_series(0, 25)', function (err, result) {
19+
assert.strictEqual(result.rows.length, 26)
20+
})
21+
client.query('SELECT * FROM NOW()', (err) => {
22+
assert(!err)
23+
release()
24+
if (++count === max) {
25+
resolve()
26+
pool.end()
27+
}
28+
})
29+
})
30+
}
31+
})
32+
})
33+
}
34+
35+
testPoolSize(1)
36+
37+
testPoolSize(2)
38+
39+
testPoolSize(40)
40+
41+
testPoolSize(200)
+1-28
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,4 @@
11
'use strict'
22
var helper = require('./../test-helper')
33

4-
const suite = new helper.Suite()
5-
6-
helper.testPoolSize = function (max) {
7-
suite.test(`test ${max} queries executed on a pool rapidly`, (cb) => {
8-
const pool = new helper.pg.Pool({ max: 10 })
9-
10-
var sink = new helper.Sink(max, function () {
11-
pool.end(cb)
12-
})
13-
14-
for (var i = 0; i < max; i++) {
15-
pool.connect(function (err, client, done) {
16-
assert(!err)
17-
client.query('SELECT * FROM NOW()')
18-
client.query('select generate_series(0, 25)', function (err, result) {
19-
assert.equal(result.rows.length, 26)
20-
})
21-
var query = client.query('SELECT * FROM NOW()', (err) => {
22-
assert(!err)
23-
sink.add()
24-
done()
25-
})
26-
})
27-
}
28-
})
29-
}
30-
31-
module.exports = Object.assign({}, helper, { suite: suite })
4+
module.exports = helper

Diff for: packages/pg/test/integration/gh-issues/2416-tests.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const helper = require('../test-helper')
2+
3+
const suite = new helper.Suite()
4+
5+
suite.testAsync('it sets search_path on connection', async () => {
6+
const client = new helper.pg.Client({
7+
options: '--search_path=foo',
8+
})
9+
await client.connect()
10+
const { rows } = await client.query('SHOW search_path')
11+
assert.strictEqual(rows.length, 1)
12+
assert.strictEqual(rows[0].search_path, 'foo')
13+
await client.end()
14+
})

Diff for: packages/pg/test/test-helper.js

-28
Original file line numberDiff line numberDiff line change
@@ -183,33 +183,6 @@ process.on('uncaughtException', function (err) {
183183
process.exit(255)
184184
})
185185

186-
var Sink = function (expected, timeout, callback) {
187-
var defaultTimeout = 5000
188-
if (typeof timeout === 'function') {
189-
callback = timeout
190-
timeout = defaultTimeout
191-
}
192-
timeout = timeout || defaultTimeout
193-
var internalCount = 0
194-
var kill = function () {
195-
assert.ok(false, 'Did not reach expected ' + expected + ' with an idle timeout of ' + timeout)
196-
}
197-
var killTimeout = setTimeout(kill, timeout)
198-
return {
199-
add: function (count) {
200-
count = count || 1
201-
internalCount += count
202-
clearTimeout(killTimeout)
203-
if (internalCount < expected) {
204-
killTimeout = setTimeout(kill, timeout)
205-
} else {
206-
assert.equal(internalCount, expected)
207-
callback()
208-
}
209-
},
210-
}
211-
}
212-
213186
var getTimezoneOffset = Date.prototype.getTimezoneOffset
214187

215188
var setTimezoneOffset = function (minutesOffset) {
@@ -231,7 +204,6 @@ const rejection = (promise) =>
231204
)
232205

233206
module.exports = {
234-
Sink: Sink,
235207
Suite: Suite,
236208
pg: require('./../lib/'),
237209
args: args,

0 commit comments

Comments
 (0)