不要怂,就是干,撸起袖子干!

Commit a7e9e2b8 by Christian Holm Committed by Sushant

fix(transaction): only rollback if connection was acquired (#9051)

1 parent ec0cb5ed
...@@ -121,13 +121,15 @@ class Transaction { ...@@ -121,13 +121,15 @@ class Transaction {
this.connection = connection; this.connection = connection;
this.connection.uuid = this.id; this.connection.uuid = this.id;
}) })
.then(() => this.begin()) .then(() => {
return this.begin()
.then(() => this.setDeferrable()) .then(() => this.setDeferrable())
.then(() => this.setIsolationLevel()) .then(() => this.setIsolationLevel())
.then(() => this.setAutocommit()) .then(() => this.setAutocommit())
.catch(setupErr => this.rollback().finally(() => { .catch(setupErr => this.rollback().finally(() => {
throw setupErr; throw setupErr;
})) }));
})
.tap(() => { .tap(() => {
if (useCLS && this.sequelize.constructor._cls) { if (useCLS && this.sequelize.constructor._cls) {
this.sequelize.constructor._cls.set('transaction', this); this.sequelize.constructor._cls.set('transaction', this);
......
...@@ -33,4 +33,22 @@ describe(Support.getTestDialectTeaser('Pooling'), function() { ...@@ -33,4 +33,22 @@ describe(Support.getTestDialectTeaser('Pooling'), function() {
return expect(this.testInstance.authenticate()) return expect(this.testInstance.authenticate())
.to.eventually.be.rejectedWith('ResourceRequest timed out'); .to.eventually.be.rejectedWith('ResourceRequest timed out');
}); });
it('should not result in unhandled promise rejection when unable to acquire connection', () => {
this.testInstance = new Sequelize('localhost', 'ffd', 'dfdf', {
dialect,
databaseVersion: '1.2.3',
pool: {
acquire: 1000,
max: 1
}
});
this.sinon.stub(this.testInstance.connectionManager, '_connect')
.returns(new Sequelize.Promise(() => {}));
return expect(this.testInstance.transaction()
.then(() => this.testInstance.transaction()))
.to.eventually.be.rejectedWith('ResourceRequest timed out');
});
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!