1 | 'use strict'
|
2 | const co = require('co')
|
3 | const expect = require('expect.js')
|
4 |
|
5 | const describe = require('mocha').describe
|
6 | const it = require('mocha').it
|
7 |
|
8 | const Pool = require('../')
|
9 |
|
10 | describe('pool ending', () => {
|
11 | it('ends without being used', (done) => {
|
12 | const pool = new Pool()
|
13 | pool.end(done)
|
14 | })
|
15 |
|
16 | it('ends with a promise', () => {
|
17 | return new Pool().end()
|
18 | })
|
19 |
|
20 | it('ends with clients', co.wrap(function * () {
|
21 | const pool = new Pool()
|
22 | const res = yield pool.query('SELECT $1::text as name', ['brianc'])
|
23 | expect(res.rows[0].name).to.equal('brianc')
|
24 | return pool.end()
|
25 | }))
|
26 |
|
27 | it('allows client to finish', co.wrap(function * () {
|
28 | const pool = new Pool()
|
29 | const query = pool.query('SELECT $1::text as name', ['brianc'])
|
30 | yield pool.end()
|
31 | const res = yield query
|
32 | expect(res.rows[0].name).to.equal('brianc')
|
33 | }))
|
34 | })
|