From ae45e09d2c09335645be748e319fa9cb652e8312 Mon Sep 17 00:00:00 2001 From: sfc-gh-ext-simba-jy Date: Sat, 23 Sep 2023 23:41:48 -0700 Subject: [PATCH 1/4] Query Context Cache integration testing fix --- test/integration/testHTAP.js | 35 ++++++++++++++++++++++++----------- test/integration/testUtil.js | 17 +++++++++++++++++ 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/test/integration/testHTAP.js b/test/integration/testHTAP.js index fb412747a..ee1a16ffa 100644 --- a/test/integration/testHTAP.js +++ b/test/integration/testHTAP.js @@ -7,24 +7,36 @@ const async = require('async'); const connOption = require('./connectionOptions').valid; const testUtil = require('./testUtil'); -// Only the AWS servers support the hybrid table in the GitHub action. +function getRandomDBNames() { + const dbName = 'qcc_test_db'; + const arr = []; + const randomNumber = Math.floor(Math.random() * 10000); + for (let i = 0; i < 3; i++){ + arr.push(dbName + (randomNumber + i)); + } + return arr; +} + if (process.env.CLOUD_PROVIDER === 'AWS') { describe('Query Context Cache test', function () { + this.retries(3); let connection; - - before(async () => { + const dbNames = getRandomDBNames(); + + beforeEach(async () => { connection = testUtil.createConnection(connOption); - await testUtil.connectAsync(connection); + testUtil.connectAsync(connection); }); after(async () => { + await testUtil.dropDBsIgnoringErrorsAsync(connection, dbNames); await testUtil.destroyConnectionAsync(connection); }); const querySet = [ { sqlTexts: [ - 'create or replace database db1', + `create or replace database ${dbNames[0]}`, 'create or replace hybrid table t1 (a int primary key, b int)', 'insert into t1 values (1, 2), (2, 3), (3, 4)' ], @@ -32,7 +44,7 @@ if (process.env.CLOUD_PROVIDER === 'AWS') { }, { sqlTexts: [ - 'create or replace database db2', + `create or replace database ${dbNames[1]}`, 'create or replace hybrid table t2 (a int primary key, b int)', 'insert into t2 values (1, 2), (2, 3), (3, 4)' ], @@ -40,7 +52,7 @@ if (process.env.CLOUD_PROVIDER === 'AWS') { }, { sqlTexts: [ - 'create or replace database db3', + `create or replace database ${dbNames[2]}`, 'create or replace hybrid table t3 (a int primary key, b int)', 'insert into t3 values (1, 2), (2, 3), (3, 4)' ], @@ -48,9 +60,9 @@ if (process.env.CLOUD_PROVIDER === 'AWS') { }, { sqlTexts: [ - 'select * from db1.public.t1 x, db2.public.t2 y, db3.public.t3 z where x.a = y.a and y.a = z.a;', - 'select * from db1.public.t1 x, db2.public.t2 y where x.a = y.a;', - 'select * from db2.public.t2 y, db3.public.t3 z where y.a = z.a;' + `select * from ${dbNames[0]}.public.t1 x, ${dbNames[1]}.public.t2 y, ${dbNames[2]}.public.t3 z where x.a = y.a and y.a = z.a;`, + `select * from ${dbNames[0]}.public.t1 x, ${dbNames[1]}.public.t2 y where x.a = y.a;`, + `select * from ${dbNames[1]}.public.t2 y, ${dbNames[2]}.public.t3 z where y.a = z.a;` ], QccSize: 4, }, @@ -92,7 +104,8 @@ if (process.env.CLOUD_PROVIDER === 'AWS') { } it('test Query Context Cache', function (done) { - async.series(createQueryTest(), done); + const queryTests = createQueryTest(); + async.series(queryTests, done); }); }); } \ No newline at end of file diff --git a/test/integration/testUtil.js b/test/integration/testUtil.js index aa05e6bf6..82b294765 100644 --- a/test/integration/testUtil.js +++ b/test/integration/testUtil.js @@ -101,6 +101,23 @@ module.exports.dropTablesIgnoringErrorsAsync = async (connection, tableNames) => } }; +/** + * Drop databases one by one if exist - any connection error is ignored + * @param connection Connection + * @param dbNames string[] + * @return {Promise} + */ +module.exports.dropDBsIgnoringErrorsAsync = async (connection, dbNames) => { + for (const dbIdx in dbNames) { + const dbName = dbNames[dbIdx]; + try { + await executeCmdAsync(connection, `DROP DATABASE IF EXISTS ${dbName}`); + } catch (e) { + console.warn(`Cannot drop database ${dbName}: ${JSON.stringify(e)}`); + } + } +}; + module.exports.checkError = function (err) { assert.ok(!err, JSON.stringify(err)); }; From 0fec081474afbb1f775602b08d7ae0c666aec440 Mon Sep 17 00:00:00 2001 From: sfc-gh-ext-simba-jy Date: Sat, 23 Sep 2023 23:49:33 -0700 Subject: [PATCH 2/4] revert some codes --- test/integration/testHTAP.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/integration/testHTAP.js b/test/integration/testHTAP.js index ee1a16ffa..febe9b7a1 100644 --- a/test/integration/testHTAP.js +++ b/test/integration/testHTAP.js @@ -17,6 +17,7 @@ function getRandomDBNames() { return arr; } +// Only the AWS servers support the hybrid table in the GitHub action. if (process.env.CLOUD_PROVIDER === 'AWS') { describe('Query Context Cache test', function () { this.retries(3); @@ -25,7 +26,7 @@ if (process.env.CLOUD_PROVIDER === 'AWS') { beforeEach(async () => { connection = testUtil.createConnection(connOption); - testUtil.connectAsync(connection); + await testUtil.connectAsync(connection); }); after(async () => { @@ -104,8 +105,7 @@ if (process.env.CLOUD_PROVIDER === 'AWS') { } it('test Query Context Cache', function (done) { - const queryTests = createQueryTest(); - async.series(queryTests, done); + async.series(createQueryTest(), done); }); }); } \ No newline at end of file From 6a8494e52a1127fa9664c1e7a5a363ef341d3716 Mon Sep 17 00:00:00 2001 From: sfc-gh-ext-simba-jy Date: Mon, 25 Sep 2023 14:33:09 -0700 Subject: [PATCH 3/4] instead of for loop, used map --- test/integration/testUtil.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/integration/testUtil.js b/test/integration/testUtil.js index 82b294765..ba46c5605 100644 --- a/test/integration/testUtil.js +++ b/test/integration/testUtil.js @@ -108,14 +108,13 @@ module.exports.dropTablesIgnoringErrorsAsync = async (connection, tableNames) => * @return {Promise} */ module.exports.dropDBsIgnoringErrorsAsync = async (connection, dbNames) => { - for (const dbIdx in dbNames) { - const dbName = dbNames[dbIdx]; + await Promise.all(dbNames.map(async (dbName) => { try { await executeCmdAsync(connection, `DROP DATABASE IF EXISTS ${dbName}`); } catch (e) { console.warn(`Cannot drop database ${dbName}: ${JSON.stringify(e)}`); } - } + })); }; module.exports.checkError = function (err) { @@ -244,4 +243,4 @@ module.exports.deleteFolderSyncIgnoringErrors = function (directory) { } catch (e) { console.warn(`Cannot delete folder ${directory}: ${JSON.stringify(e)}`); } -}; +}; \ No newline at end of file From 19bc6878d11379cd954eae268405dbc7f532c183 Mon Sep 17 00:00:00 2001 From: sfc-gh-ext-simba-jy Date: Mon, 25 Sep 2023 15:00:56 -0700 Subject: [PATCH 4/4] replaced promise map, I used for of loop --- test/integration/testUtil.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/integration/testUtil.js b/test/integration/testUtil.js index ba46c5605..ce9812077 100644 --- a/test/integration/testUtil.js +++ b/test/integration/testUtil.js @@ -108,13 +108,13 @@ module.exports.dropTablesIgnoringErrorsAsync = async (connection, tableNames) => * @return {Promise} */ module.exports.dropDBsIgnoringErrorsAsync = async (connection, dbNames) => { - await Promise.all(dbNames.map(async (dbName) => { + for (const dbName of dbNames) { try { await executeCmdAsync(connection, `DROP DATABASE IF EXISTS ${dbName}`); } catch (e) { console.warn(`Cannot drop database ${dbName}: ${JSON.stringify(e)}`); } - })); + } }; module.exports.checkError = function (err) { @@ -243,4 +243,4 @@ module.exports.deleteFolderSyncIgnoringErrors = function (directory) { } catch (e) { console.warn(`Cannot delete folder ${directory}: ${JSON.stringify(e)}`); } -}; \ No newline at end of file +};