query.test.js
1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
const chai = require('chai'),
sinon = require('sinon'),
expect = chai.expect,
Support = require(__dirname + '/support'),
Sequelize = Support.Sequelize,
Promise = Sequelize.Promise,
current = Support.sequelize;
describe('sequelize.query', () => {
it('connection should be released only once when retry fails', () => {
const getConnectionStub = sinon.stub(current.connectionManager, 'getConnection').callsFake(() => {
return Promise.resolve({});
});
const releaseConnectionStub = sinon.stub(current.connectionManager, 'releaseConnection').callsFake(() => {
return Promise.resolve();
});
const queryStub = sinon.stub(current.dialect.Query.prototype, 'run').callsFake(() => {
return Promise.reject(new Error('wrong sql'));
});
return current.query('THIS IS A WRONG SQL', {
retry: {
max: 2,
// retry for all errors
match: null
}
})
.catch(() => {})
.finally(() => {
expect(releaseConnectionStub).have.been.calledOnce;
queryStub.restore();
getConnectionStub.restore();
releaseConnectionStub.restore();
});
});
});