From 3f0459ff926a8c10accf45d487d3d20768c0ff21 Mon Sep 17 00:00:00 2001 From: Przemyslaw Motacki Date: Wed, 4 Oct 2023 13:55:10 +0200 Subject: [PATCH] SNOW-930831: Add randomization to the table name in put/get test --- test/integration/testConnectionPoolExecute.js | 32 +++++++++++-------- test/integration/testLargeResultSet.js | 19 ++++++----- test/integration/testPutGet.js | 10 ++++-- test/integration/testPutSmallFiles.js | 12 ++++--- test/integration/testUtil.js | 12 +++++++ 5 files changed, 56 insertions(+), 29 deletions(-) diff --git a/test/integration/testConnectionPoolExecute.js b/test/integration/testConnectionPoolExecute.js index 8aabbad8b..5f0923987 100644 --- a/test/integration/testConnectionPoolExecute.js +++ b/test/integration/testConnectionPoolExecute.js @@ -4,14 +4,16 @@ const async = require('async'); const testUtil = require('./testUtil'); +const {randomizeName} = require('./testUtil'); describe('Execute test with Pool', function () { let connectionPool = null; - const createNodeTSQL = 'create or replace table NodeT(colA number, colB varchar)'; - const selectAllSQL = 'select * from NodeT'; - const insertNodeTSQL = 'insert into NodeT values(1, \'a\')'; - const updateNodeTSQL = 'update NodeT set COLA = 2, COLB = \'b\' where COLA = 1'; - const dropNodeTSQL = 'drop table if exists NodeT'; + const nodeT= randomizeName('nodeT'); + const createNodeTSQL = `create or replace table ${nodeT}(colA number, colB varchar)`; + const selectAllSQL = `select * from ${nodeT}`; + const insertNodeTSQL = `insert into ${nodeT} values(1, \'a\')`; + const updateNodeTSQL = `update ${nodeT} set COLA = 2, COLB = \'b\' where COLA = 1`; + const dropNodeTSQL = `drop table if exists ${nodeT}`; before(function (done) { connectionPool = testUtil.createConnectionPool(); @@ -90,7 +92,7 @@ describe('Execute test with Pool', function () { testUtil.executeQueryAndVerifyUsePool( connectionPool, createNodeTSQL, - [{'status': 'Table NODET successfully created.'}], + [{'status': `Table ${nodeT} successfully created.`}], callback ); }, @@ -109,14 +111,16 @@ describe('Execute test with Pool', function () { describe('Execute test use Pool for multiple connections', function () { let connectionPool = null; - const createNodeASQL = 'create or replace table NodeA(colA number, colB varchar);'; - const createNodeBSQL = 'create or replace table NodeB(colA number, colB varchar);'; - const selectAllSQLFromNodeA = 'select * from NodeA;'; - const selectAllSQLFromNodeB = 'select * from NodeB;'; - const insertNodeASQL = 'insert into NodeA values(1, \'a\');'; - const insertNodeBSQL = 'insert into NodeB values(1, \'b\');'; - const dropNodeASQL = 'drop table if exists NodeA;'; - const dropNodeBSQL = 'drop table if exists NodeB;'; + const nodeA = randomizeName('NodeA'); + const nodeB = randomizeName('NodeB'); + const createNodeASQL = `create or replace table ${nodeA} (colA number, colB varchar);`; + const createNodeBSQL = `create or replace table ${nodeB}(colA number, colB varchar);`; + const selectAllSQLFromNodeA = `select * from ${nodeA};`; + const selectAllSQLFromNodeB = `select * from {nodeB};`; + const insertNodeASQL = `insert into ${nodeA} values(1, \`a\`);`; + const insertNodeBSQL = `insert into {nodeB} values(1, \`b\`);`; + const dropNodeASQL = `drop table if exists ${nodeA};`; + const dropNodeBSQL = `drop table if exists {nodeB};`; before(function (done) { connectionPool = testUtil.createConnectionPool(); diff --git a/test/integration/testLargeResultSet.js b/test/integration/testLargeResultSet.js index 79d6194c9..8ea81853b 100644 --- a/test/integration/testLargeResultSet.js +++ b/test/integration/testLargeResultSet.js @@ -5,6 +5,7 @@ const assert = require('assert'); const async = require('async'); const testUtil = require('./testUtil'); const { configureLogger } = require('../configureLogger'); +const {randomizeName} = require('./testUtil'); describe('Large result Set Tests', function () { @@ -110,10 +111,12 @@ describe('Large result Set Tests', function () describe('Large Result Set Tests For Variant Column Type', function () { - const createTempTable = 'create or replace table testVariantTemp(value string)'; - const createTableWithVariant = 'create or replace table testVariantTable(colA variant)'; - const dropTableWithVariant = 'drop table if exists testVariantTable'; - const dropTempTable = 'drop table if exists testVariantTemp'; + const testVariantTemp = randomizeName('testVariantTemp'); + const testVariantTable = randomizeName('testVariantTable'); + const createTempTable = `create or replace table ${testVariantTemp} (value string)`; + const createTableWithVariant = `create or replace table ${testVariantTable} (colA variant)`; + const dropTableWithVariant = `drop table if exists ${testVariantTable}`; + const dropTempTable = `drop table if exists ${testVariantTemp} `; before(async () => { @@ -129,9 +132,9 @@ describe('Large result Set Tests', function () it('testSelectOnVariantColumnForLargeResultSets', function (done) { - const insertTemp = 'insert into testVariantTemp values (?)'; - const insertVariant = 'insert into testVariantTable select parse_json(value) from testVariantTemp'; - const selectVariant = 'select * from testVariantTable'; + const insertTemp = `insert into ${testVariantTemp} values (?)`; + const insertVariant = `insert into ${testVariantTable} select parse_json(value) from ${testVariantTemp}`; + const selectVariant = `select * from ${testVariantTable}`; const arrJSON = []; for (let i = 0; i < sourceRowCount; i++) @@ -254,7 +257,7 @@ describe('Large result Set Tests', function () describe('SNOW-743920:Large result set with ~35 chunks', function () { let connection; - const tableName = 'test_table'; + const tableName = randomizeName('test_table'); const sourceRowCount = 251002; const generatedRowSize = 350; const createTable = `create or replace table ${tableName} (data string)`; diff --git a/test/integration/testPutGet.js b/test/integration/testPutGet.js index 2e5ef67a0..53b650f21 100644 --- a/test/integration/testPutGet.js +++ b/test/integration/testPutGet.js @@ -12,10 +12,10 @@ const tmp = require('tmp'); const os = require('os'); const path = require('path'); const zlib = require('zlib'); +const {randomizeName} = require("./testUtil"); const DATABASE_NAME = connOption.valid.database; const SCHEMA_NAME = connOption.valid.schema; -const TEMP_TABLE_NAME = 'TEMP_TABLE'; const SKIPPED = 'SKIPPED'; const UPLOADED = 'UPLOADED'; @@ -75,6 +75,7 @@ describe('PUT GET test', function () { let connection; let tmpFile; + const TEMP_TABLE_NAME = randomizeName('TEMP_TABLE'); const createTable = `create or replace table ${TEMP_TABLE_NAME} (${COL1} STRING, ${COL2} STRING, ${COL3} STRING)`; const truncateTable = `truncate table if exists ${TEMP_TABLE_NAME}`; const copyInto = `COPY INTO ${TEMP_TABLE_NAME}`; @@ -292,6 +293,7 @@ describe('PUT GET overwrite test', function () { this.retries(3); // this test suit are considered as flaky test let connection; + const TEMP_TABLE_NAME = randomizeName('TEMP_TABLE'); const createTable = `create or replace table ${TEMP_TABLE_NAME} (${COL1} STRING, ${COL2} STRING, ${COL3} STRING)`; const removeFile = `REMOVE @${DATABASE_NAME}.${SCHEMA_NAME}.%${TEMP_TABLE_NAME}`; const dropTable = `DROP TABLE IF EXISTS ${TEMP_TABLE_NAME}`; @@ -477,8 +479,8 @@ describe('PUT GET test with GCS_USE_DOWNSCOPED_CREDENTIAL', function () { this.retries(3); // this test suit are considered as flaky test let connection; - let tmpFile; + const TEMP_TABLE_NAME = randomizeName('TEMP_TABLE'); const createTable = `create or replace table ${TEMP_TABLE_NAME} (${COL1} STRING, ${COL2} STRING, ${COL3} STRING)`; const copyInto = `COPY INTO ${TEMP_TABLE_NAME}`; const removeFile = `REMOVE @${DATABASE_NAME}.${SCHEMA_NAME}.%${TEMP_TABLE_NAME}`; @@ -649,6 +651,7 @@ describe('PUT GET test with GCS_USE_DOWNSCOPED_CREDENTIAL', function () { describe('PUT GET test with multiple files', function () { let connection; let tmpDir; + const TEMP_TABLE_NAME = randomizeName('TEMP_TABLE'); const stage = `@${DATABASE_NAME}.${SCHEMA_NAME}.%${TEMP_TABLE_NAME}`; const removeFile = `REMOVE ${stage}`; let tmpFiles; // FileSyncObject[] @@ -862,6 +865,7 @@ describe('PUT GET test with multiple files', function () { describe('PUT GET test without compress', function () { let connection; + const TEMP_TABLE_NAME = randomizeName('TEMP_TABLE'); const stage = `@${DATABASE_NAME}.${SCHEMA_NAME}.%${TEMP_TABLE_NAME}`; const createTable = `create or replace table ${TEMP_TABLE_NAME} (${COL1} STRING, ${COL2} STRING, ${COL3} STRING)`; const removeFile = `REMOVE ${stage}`; @@ -959,6 +963,7 @@ describe('PUT GET test without compress', function () { describe('PUT GET test with different size', function () { let connection; + const TEMP_TABLE_NAME = randomizeName('TEMP_TABLE'); const stage = `@${DATABASE_NAME}.${SCHEMA_NAME}.%${TEMP_TABLE_NAME}`; const createTable = `create or replace table ${TEMP_TABLE_NAME} (${COL1} STRING, ${COL2} STRING, ${COL3} STRING)`; const removeFile = `REMOVE ${stage}`; @@ -1092,6 +1097,7 @@ describe('PUT GET test with different size', function () { describe('PUT GET test with error', function () { let connection; + const TEMP_TABLE_NAME = randomizeName('TEMP_TABLE'); const stage = `@${DATABASE_NAME}.${SCHEMA_NAME}.%${TEMP_TABLE_NAME}`; const stage_not_exist = `@${DATABASE_NAME}.${SCHEMA_NAME}.%NONEXISTTABLE`; const createTable = `create or replace table ${TEMP_TABLE_NAME} (${COL1} STRING, ${COL2} STRING, ${COL3} STRING)`; diff --git a/test/integration/testPutSmallFiles.js b/test/integration/testPutSmallFiles.js index 78b352d91..81e7b1c96 100644 --- a/test/integration/testPutSmallFiles.js +++ b/test/integration/testPutSmallFiles.js @@ -8,10 +8,12 @@ var os = require('os'); var path = require('path'); var testUtil = require('./testUtil'); const connOption = require('./connectionOptions'); +const {randomizeName} = require('./testUtil'); const DATABASE_NAME = connOption.valid.database; const SCHEMA_NAME = connOption.valid.schema; const WAREHOUSE_NAME = connOption.valid.warehouse; +const TABLE = randomizeName('TESTTBL'); var connection; var files = new Array(); @@ -20,7 +22,7 @@ function uploadFiles(callback, index = 0) { if(index < files.length) { - var putQuery = `PUT file://${files[index]} @${DATABASE_NAME}.${SCHEMA_NAME}.%TESTTBL`; + var putQuery = `PUT file://${files[index]} @${DATABASE_NAME}.${SCHEMA_NAME}.%${TABLE}`; var insertStmt = connection.execute({ sqlText: putQuery, complete: function (err, stmt) { @@ -46,10 +48,10 @@ describe('Test Put Small Files', function () { this.timeout(100000); var useWH = `use warehouse ${WAREHOUSE_NAME}`; - var createTable = `create or replace table ${DATABASE_NAME}.${SCHEMA_NAME}.TESTTBL(colA string, colB number, colC date, colD time, colE TIMESTAMP_NTZ, colF TIMESTAMP_TZ)`; - var copytInto = `copy into ${DATABASE_NAME}.${SCHEMA_NAME}.TESTTBL`; - var select1row = `select * from ${DATABASE_NAME}.${SCHEMA_NAME}.TESTTBL where colB = 3`; - var selectAll = `select count(*) AS NUM from ${DATABASE_NAME}.${SCHEMA_NAME}.TESTTBL`; + var createTable = `create or replace table ${DATABASE_NAME}.${SCHEMA_NAME}.${TABLE}(colA string, colB number, colC date, colD time, colE TIMESTAMP_NTZ, colF TIMESTAMP_TZ)`; + var copytInto = `copy into ${DATABASE_NAME}.${SCHEMA_NAME}.${TABLE}`; + var select1row = `select * from ${DATABASE_NAME}.${SCHEMA_NAME}.${TABLE} where colB = 3`; + var selectAll = `select count(*) AS NUM from ${DATABASE_NAME}.${SCHEMA_NAME}.${TABLE}`; var count = 5000; before(function (done) diff --git a/test/integration/testUtil.js b/test/integration/testUtil.js index ce9812077..a57131660 100644 --- a/test/integration/testUtil.js +++ b/test/integration/testUtil.js @@ -5,6 +5,7 @@ const snowflake = require('./../../lib/snowflake'); const connOptions = require('./connectionOptions'); const assert = require('assert'); const fs = require('fs'); +const crypto = require('crypto'); module.exports.createConnection = function (validConnectionOptionsOverride = {}) { return snowflake.createConnection({ @@ -244,3 +245,14 @@ module.exports.deleteFolderSyncIgnoringErrors = function (directory) { console.warn(`Cannot delete folder ${directory}: ${JSON.stringify(e)}`); } }; + +/** + * @param name string + */ +module.exports.randomizeName = function (name) { + if (name === null || name.trim() === '') { + throw new Error('Name must be non empty string'); + } + const randomString = crypto.randomBytes(4).toString('hex'); + return name.concat(randomString); +};