From 82e50cda16456f7a35a2446080c72d9057f78723 Mon Sep 17 00:00:00 2001 From: Pieterjan Spoelders Date: Thu, 7 Nov 2024 05:27:21 -0500 Subject: [PATCH] Added an integration test for the ExasolPool running 4 queries simultaneously --- integration-test/testcases/pool.basic.spec.ts | 83 +++++++++++++++---- 1 file changed, 66 insertions(+), 17 deletions(-) diff --git a/integration-test/testcases/pool.basic.spec.ts b/integration-test/testcases/pool.basic.spec.ts index ac4fe42..dc1f306 100644 --- a/integration-test/testcases/pool.basic.spec.ts +++ b/integration-test/testcases/pool.basic.spec.ts @@ -26,7 +26,27 @@ export const basicPoolTests = (name: string, factory: websocketFactory) => }); it('Connect to DB', async () => { - //ACQUIRE AND DESTROY + const poolToQuery = new ExasolPool(factory, { + host: container.getHost(), + port: container.getMappedPort(8563), + user: 'sys', + password: 'exasol', + encryption: false, + min: 1, + max: 10, + }); + await poolToQuery.drain(); + await poolToQuery.clear(); + }); + + it('Fetch multiple queries simultaneously/asynchronously', async () => { + const setupClient = new ExasolDriver(factory, { + host: container.getHost(), + port: container.getMappedPort(8563), + user: 'sys', + password: 'exasol', + encryption: false, + }); const poolToQuery = new ExasolPool(factory, { host: container.getHost(), @@ -37,18 +57,48 @@ export const basicPoolTests = (name: string, factory: websocketFactory) => min: 1, max: 10, }); + + await setupClient.connect(); + + await setupClient.execute('CREATE SCHEMA ' + schemaName); + await setupClient.execute('CREATE TABLE ' + schemaName + '.TEST_TABLE(x INT)'); + await setupClient.execute('INSERT INTO ' + schemaName + '.TEST_TABLE VALUES (15)'); + + const dataPromise1 = poolToQuery.query('SELECT x FROM ' + schemaName + '.TEST_TABLE'); + const dataPromise2 = poolToQuery.query('SELECT x FROM ' + schemaName + '.TEST_TABLE'); + const dataPromise3 = poolToQuery.query('SELECT x FROM ' + schemaName + '.TEST_TABLE'); + const dataPromise4 = poolToQuery.query('SELECT x FROM ' + schemaName + '.TEST_TABLE'); + + const data1 = await dataPromise1; + expect(await data1.getColumns()[0].name).toBe('X'); + expect(await data1.getRows()[0]['X']).toBe(15); + + const data2 = await dataPromise2; + expect(await data2.getColumns()[0].name).toBe('X'); + expect(await data2.getRows()[0]['X']).toBe(15); + + const data3 = await dataPromise3; + expect(await data3.getColumns()[0].name).toBe('X'); + expect(await data3.getRows()[0]['X']).toBe(15); + + const data4 = await dataPromise4; + expect(await data4.getColumns()[0].name).toBe('X'); + expect(await data4.getRows()[0]['X']).toBe(15); + await poolToQuery.drain(); await poolToQuery.clear(); + + await setupClient.close(); }); it('Exec and fetch', async () => { - // const setupClient = new ExasolDriver(factory, { - // host: container.getHost(), - // port: container.getMappedPort(8563), - // user: 'sys', - // password: 'exasol', - // encryption: false, - // }); + const setupClient = new ExasolDriver(factory, { + host: container.getHost(), + port: container.getMappedPort(8563), + user: 'sys', + password: 'exasol', + encryption: false, + }); const poolToQuery = new ExasolPool(factory, { host: container.getHost(), @@ -60,17 +110,16 @@ export const basicPoolTests = (name: string, factory: websocketFactory) => max: 10, }); - // await setupClient.connect(); + await setupClient.connect(); - // await setupClient.execute('CREATE SCHEMA ' + schemaName); - // await setupClient.execute('CREATE TABLE ' + schemaName + '.TEST_TABLE(x INT)'); - // await setupClient.execute('INSERT INTO ' + schemaName + '.TEST_TABLE VALUES (15)'); + await setupClient.execute('CREATE SCHEMA ' + schemaName); + await setupClient.execute('CREATE TABLE ' + schemaName + '.TEST_TABLE(x INT)'); + await setupClient.execute('INSERT INTO ' + schemaName + '.TEST_TABLE VALUES (15)'); - // //const data = await poolToQuery.query('SELECT x FROM ' + schemaName + '.TEST_TABLE'); - // const data = await setupClient.query('SELECT x FROM ' + schemaName + '.TEST_TABLE'); + const data = await poolToQuery.query('SELECT x FROM ' + schemaName + '.TEST_TABLE'); - // expect(data.getColumns()[0].name).toBe('X'); - // expect(data.getRows()[0]['X']).toBe(15); + expect(data.getColumns()[0].name).toBe('X'); + expect(data.getRows()[0]['X']).toBe(15); // poolToQuery.drain().then(function () { // poolToQuery.clear(); @@ -78,7 +127,7 @@ export const basicPoolTests = (name: string, factory: websocketFactory) => await poolToQuery.drain(); await poolToQuery.clear(); - //await setupClient.close(); + await setupClient.close(); }); // it('Exec and fetch (raw)', async () => {