feat: add is active check for transaction
This commit is contained in:
parent
61766bb0da
commit
40b06b1467
|
@ -134,3 +134,10 @@ Transaction.begin = function(connector, options, cb) {
|
||||||
});
|
});
|
||||||
if (cb.promise) return cb.promise;
|
if (cb.promise) return cb.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether a transaction has an active connection.
|
||||||
|
*/
|
||||||
|
Transaction.prototype.isActive = function() {
|
||||||
|
return !!this.connection;
|
||||||
|
}
|
||||||
|
|
|
@ -210,6 +210,32 @@ describe('transactions', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('isActive', function() {
|
||||||
|
it('returns true when connection is active', function(done) {
|
||||||
|
Post.beginTransaction({
|
||||||
|
isolationLevel: Transaction.READ_COMMITTED,
|
||||||
|
timeout: 1000,
|
||||||
|
},
|
||||||
|
function(err, tx) {
|
||||||
|
if (err) return done(err);
|
||||||
|
expect(tx.isActive()).to.equal(true);
|
||||||
|
return done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('returns false when connection is not active', function(done) {
|
||||||
|
Post.beginTransaction({
|
||||||
|
isolationLevel: Transaction.READ_COMMITTED,
|
||||||
|
timeout: 1000,
|
||||||
|
},
|
||||||
|
function(err, tx) {
|
||||||
|
if (err) return done(err);
|
||||||
|
delete tx.connection;
|
||||||
|
expect(tx.isActive()).to.equal(false);
|
||||||
|
return done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('transaction instance', function() {
|
describe('transaction instance', function() {
|
||||||
function TestTransaction(connector, connection) {
|
function TestTransaction(connector, connection) {
|
||||||
this.connector = connector;
|
this.connector = connector;
|
||||||
|
|
Loading…
Reference in New Issue