Skip to content

Commit fabf39c

Browse files
charmanderbrianc
authored andcommitted
Count only test query itself (#87)
* Count only test query itself This breaks more obviously in PostgreSQL 10 (https://wiki.postgresql.org/wiki/New_in_postgres_10#Significant_Expansion_of_Wait_Events_in_pg_stat_activity). * Fix query counting for PostgreSQL 9.1
1 parent 2f14cb1 commit fabf39c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

test/sizing.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,17 @@ describe('pool size of 1', () => {
3333

3434
it('can only send 1 query at a time', co.wrap(function * () {
3535
const pool = new Pool({ max: 1 })
36-
const queries = _.times(20, (i) => {
37-
return pool.query('SELECT COUNT(*) as counts FROM pg_stat_activity')
38-
})
36+
37+
// the query text column name changed in PostgreSQL 9.2
38+
const versionResult = yield pool.query('SHOW server_version_num')
39+
const version = parseInt(versionResult.rows[0].server_version_num, 10)
40+
const queryColumn = version < 90200 ? 'current_query' : 'query'
41+
42+
const queryText = 'SELECT COUNT(*) as counts FROM pg_stat_activity WHERE ' + queryColumn + ' = $1'
43+
const queries = _.times(20, () =>
44+
pool.query(queryText, [queryText]))
3945
const results = yield Promise.all(queries)
40-
const counts = results.map(res => parseInt(res.rows[0].counts), 10)
46+
const counts = results.map(res => parseInt(res.rows[0].counts, 10))
4147
expect(counts).to.eql(_.times(20, i => 1))
4248
return yield pool.end()
4349
}))

0 commit comments

Comments
 (0)