From a1062501e74c8d50637c114b550232924d8a7c61 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Wed, 3 Mar 2021 17:46:41 -0600 Subject: [PATCH] connection_pool tests --- src/__tests__/connection_pool.test.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/__tests__/connection_pool.test.js b/src/__tests__/connection_pool.test.js index 01b1dbd..2298e28 100644 --- a/src/__tests__/connection_pool.test.js +++ b/src/__tests__/connection_pool.test.js @@ -11,7 +11,6 @@ test(`construction fails if pool size is <= 1`, () => { }); test(`error on socket release is ignored`, async () => { - const conn = new connection_pool(2, '', 20000); let invoked = false; jest.spyOn(conn.pool, 'acquire').mockImplementation(() => { @@ -33,7 +32,7 @@ test(`error on socket release is ignored`, async () => { expect(invoked).toBeTruthy(); }); -test(`send fails if acquire fails`, async () => { +test(`connection pool send fails if socket acquire fails`, async () => { const conn = new connection_pool(2, '', 20000); jest.spyOn(conn.pool, 'acquire').mockImplementation(() => { throw new Error('mock acquire exception'); @@ -41,3 +40,21 @@ test(`send fails if acquire fails`, async () => { await expect(conn.send('', new packet())).rejects.toThrow(Error); }); + +test(`connection pool send fails when connection send fails`, async () => { + const conn = new connection_pool(2, '', 20000); + jest.spyOn(conn.pool, 'acquire').mockImplementation(() => { + return { + release: () => { + }, + } + }); + + const mock_send = jest.fn(); + connection.prototype.send = async () => { + return mock_send(); + }; + mock_send.mockRejectedValue(new Error('mock send failed')); + + await expect(conn.send('', new packet())).rejects.toThrow(Error); +});