with-connection.test.ts 780 B

123456789101112131415161718192021222324
  1. import { expect } from 'chai';
  2. import { createSingleTestSequelizeInstance } from '../support';
  3. describe('sequelize.withConnection', () => {
  4. it('reserves a connection, to ensure multiple queries run on the same connection', async () => {
  5. const sequelize = createSingleTestSequelizeInstance();
  6. await sequelize.withConnection(async () => {
  7. expect(sequelize.pool.using).to.eq(1);
  8. });
  9. expect(sequelize.pool.available).to.eq(1);
  10. });
  11. it('has an option to kill the connection after using it', async () => {
  12. const sequelize = createSingleTestSequelizeInstance();
  13. await sequelize.withConnection({ destroyConnection: true }, async () => {
  14. expect(sequelize.pool.using).to.eq(1);
  15. });
  16. expect(sequelize.pool.available).to.eq(0);
  17. });
  18. });