Skip to content

Commit

Permalink
Simplify the test and lower the time to 1sec
Browse files Browse the repository at this point in the history
  • Loading branch information
wubzz committed Feb 3, 2016
1 parent 57bac6c commit 4244bb1
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions test/integration/builder/transaction.js
Expand Up @@ -279,39 +279,33 @@ module.exports = function(knex) {

});

it('#1040, #1171 - When pool is filled with transaction connections, Non-transaction queries should not hang the application, but instead throw a timeout error', function(done) {
this.timeout(15000);
it('#1040, #1171 - When pool is filled with transaction connections, Non-transaction queries should not hang the application, but instead throw a timeout error', function() {
//To make this test easier, I'm changing the pool settings to max 1.
var knexConfig = _.clone(knex.client.config);
knexConfig.pool.min = 0;
knexConfig.pool.max = 1;
knexConfig.acquireConnectionTimeout = 10000;
knexConfig.acquireConnectionTimeout = 1000;

var knexDb = new Knex(knexConfig);

//Create a transaction that will occupy the only available connection, and avoid trx.commit.
knexDb.transaction(function(trx) {
trx.raw('SELECT 1 = 1').then(function() {

//No connection is available, so try issuing a query without transaction.
//Since there is no available connection, it should throw a timeout error based on `aquireConnectionTimeout` from the knex config.
knexDb.raw('select * FROM accounts WHERE username = ?', ['Test'])
.then(function(res) {
expect(res).to.not.exist();
})
.catch(function(error) {
expect(error.bindings).to.be.an('array');
expect(error.bindings[0]).to.equal('Test');
expect(error.sql).to.equal('select * FROM accounts WHERE username = ?');
expect(error.message).to.equal('Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?');
trx.commit();
});
}).catch(trx.rollback);
})
.then(function() {
done();
})
.catch(done);
return knexDb.transaction(function(trx) {
trx.raw('SELECT 1 = 1').then(function () {
//No connection is available, so try issuing a query without transaction.
//Since there is no available connection, it should throw a timeout error based on `aquireConnectionTimeout` from the knex config.
return knexDb.raw('select * FROM accounts WHERE username = ?', ['Test'])
})
.then(function () {
//Should never reach this point
expect(false).to.be.ok();
}).catch(function (error) {
expect(error.bindings).to.be.an('array');
expect(error.bindings[0]).to.equal('Test');
expect(error.sql).to.equal('select * FROM accounts WHERE username = ?');
expect(error.message).to.equal('Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?');
trx.commit();//Test done
});
});
});

});
Expand Down

0 comments on commit 4244bb1

Please sign in to comment.