diff --git a/lib/core.js b/lib/core.js index 14df6e3e8..ac46cce00 100644 --- a/lib/core.js +++ b/lib/core.js @@ -300,7 +300,11 @@ function Core(options) // avoid infinite loop if factory creation fails connectionPool.on('factoryCreateError', function(err) { - const clientResourceRequest = connectionPool._waitingClientsQueue.dequeue(); + const clientResourceRequest = connectionPool._waitingClientsQueue.dequeue(); + if (clientResourceRequest) + { + clientResourceRequest.reject(err); + } }) return connectionPool; diff --git a/test/integration/testConnection.js b/test/integration/testConnection.js index f23d7b302..594b1ee98 100644 --- a/test/integration/testConnection.js +++ b/test/integration/testConnection.js @@ -1081,7 +1081,7 @@ describe('Connection test - connection pool', function () }); }); - it('wrong password', function (done) + it('wrong password - use', async function () { var connectionPool = snowflake.createPool(connOption.wrongPwd, { @@ -1093,15 +1093,42 @@ describe('Connection test - connection pool', function () assert.equal(connectionPool.min, 1); assert.equal(connectionPool.size, 1); - // Use the connection pool, automatically creates a new connection - connectionPool.use(async (connection) => + try { - assert.ok(connection.isUp(), "not active"); + // Use the connection pool, automatically creates a new connection + await connectionPool.use(async (connection) => + { + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.size, 1); + }); + } + catch (err) + { + assert.strictEqual(err.message, "Incorrect username or password was specified."); + } + }); + + it('wrong password - acquire', async function () + { + var connectionPool = snowflake.createPool(connOption.wrongPwd, + { + max: 10, + min: 1 + }); + + assert.equal(connectionPool.max, 10); + assert.equal(connectionPool.min, 1); assert.equal(connectionPool.size, 1); + + try + { + await connectionPool.acquire(); + } + catch (err) + { + assert.strictEqual(err.message, "Incorrect username or password was specified."); + } }); - // no login loop with wrong password - done(); - }); }); describe('Heartbeat test', function ()