1 | const Pool = require('../')
|
2 |
|
3 | const expect = require('expect.js')
|
4 | const net = require('net')
|
5 |
|
6 | describe('releasing clients', () => {
|
7 | it('removes a client which cannot be queried', async () => {
|
8 |
|
9 | const pool = new Pool({ max: 1 })
|
10 | expect(pool.totalCount).to.eql(0)
|
11 | const client = await pool.connect()
|
12 | expect(pool.totalCount).to.eql(1)
|
13 | expect(pool.idleCount).to.eql(0)
|
14 |
|
15 | client.connection.end()
|
16 |
|
17 |
|
18 | const err = await new Promise((resolve) => client.once('error', resolve))
|
19 | expect(err).to.be.ok()
|
20 | expect(pool.totalCount).to.eql(1)
|
21 | expect(pool.idleCount).to.eql(0)
|
22 |
|
23 |
|
24 | client.release()
|
25 | expect(pool.totalCount).to.eql(0)
|
26 | expect(pool.idleCount).to.eql(0)
|
27 |
|
28 |
|
29 | const { rows } = await pool.query('SELECT NOW()')
|
30 | expect(rows).to.have.length(1)
|
31 | await pool.end()
|
32 | })
|
33 |
|
34 | it('removes a client which is ending', async () => {
|
35 |
|
36 | const pool = new Pool({ max: 1 })
|
37 | expect(pool.totalCount).to.eql(0)
|
38 | const client = await pool.connect()
|
39 | expect(pool.totalCount).to.eql(1)
|
40 | expect(pool.idleCount).to.eql(0)
|
41 |
|
42 | client.end()
|
43 |
|
44 |
|
45 | client.release()
|
46 | expect(pool.totalCount).to.eql(0)
|
47 | expect(pool.idleCount).to.eql(0)
|
48 |
|
49 |
|
50 | const { rows } = await pool.query('SELECT NOW()')
|
51 | expect(rows).to.have.length(1)
|
52 | await pool.end()
|
53 | })
|
54 | })
|