ending.js 907 B

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