Skip to content

Commit

Permalink
Query Context Cache integration testing fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-jy committed Sep 24, 2023
1 parent 5dcb8fc commit ae45e09
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
35 changes: 24 additions & 11 deletions test/integration/testHTAP.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,62 @@ 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)'
],
QccSize: 2,
},
{
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)'
],
QccSize: 3,
},
{
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)'
],
QccSize: 4,
},
{
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,
},
Expand Down Expand Up @@ -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);
});
});
}
17 changes: 17 additions & 0 deletions test/integration/testUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>}
*/
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));
};
Expand Down

0 comments on commit ae45e09

Please sign in to comment.