Fix SODA collection test not closing message in soda5.js
This commit is contained in:
parent
7738361b84
commit
377acf3642
|
@ -30,7 +30,7 @@ const configList = [
|
|||
"\t* NODE_ORACLEDB_PASSWORD\n" +
|
||||
"\t* NODE_ORACLEDB_CONNECTIONSTRING\n",
|
||||
}
|
||||
]
|
||||
];
|
||||
|
||||
if (dbconfig.test.DBA_PRIVILEGE) {
|
||||
configList.push({
|
||||
|
@ -86,7 +86,7 @@ before(function(done) {
|
|||
conn.execute(
|
||||
"select * from dual",
|
||||
function(err, result) {
|
||||
if (!Boolean(err) && Boolean(result.rows) && (result.rows[0][0]==="X")) {
|
||||
if (!err && result.rows && (result.rows[0][0]==="X")) {
|
||||
cb(null, index);
|
||||
} else {
|
||||
cb(new Error("Query test failed"), index);
|
||||
|
@ -95,7 +95,7 @@ before(function(done) {
|
|||
);
|
||||
});
|
||||
seriesList.push(function (cb) {
|
||||
conn.close(function (err) {cb(err, index)});
|
||||
conn.close(function (err) {cb(err, index);});
|
||||
});
|
||||
});
|
||||
async.series(seriesList, function(err, results) {
|
||||
|
|
|
@ -487,7 +487,7 @@ describe('173. soda5.js', () => {
|
|||
await dropIdxOpt(options);
|
||||
}); // 173.11
|
||||
|
||||
it('173.12 getDataGiuide(), basic case', async () => {
|
||||
it('173.12 getDataGuide(), basic case', async () => {
|
||||
|
||||
let conn, collection;
|
||||
|
||||
|
@ -512,54 +512,50 @@ describe('173. soda5.js', () => {
|
|||
should.not.exist(err);
|
||||
}
|
||||
|
||||
let compatibleVersion;
|
||||
if (dbconfig.test.DBA_PRIVILEGE) {
|
||||
try {
|
||||
const connectionDetails = {
|
||||
user : dbconfig.test.DBA_user,
|
||||
password : dbconfig.test.DBA_password,
|
||||
connectString : dbconfig.connectString,
|
||||
privilege : oracledb.SYSDBA,
|
||||
};
|
||||
let conn = await oracledb.getConnection(connectionDetails);
|
||||
let res = await conn.execute("select name, value from v$parameter where name like lower('%'||:x||'%')", ['COMPATIBLE']);
|
||||
if(res.rows.length > 0) {
|
||||
compatibleVersion = res.rows[0][1];
|
||||
}
|
||||
await conn.close();
|
||||
} catch (err) {
|
||||
should.not.exist(err);
|
||||
}
|
||||
}
|
||||
const isCreateIndexEnabled = sodaUtil.versionStringCompare(compatibleVersion, '12.2.0.0.0');
|
||||
/*
|
||||
* if isCreateIndexEligible >= 0: Can Create Index without error
|
||||
* if isCreateIndexEligible < 0: Create Index will throw error ORA-00406
|
||||
* if isCreateIndexEligible = undefined: Getting COMPATIBLE VERSION string failed, the following part is skipped
|
||||
*/
|
||||
const isCreateIndexEligible = testsUtil.versionStringCompare(await testsUtil.getDBCompatibleVersion(), '12.2.0.0.0');
|
||||
try {
|
||||
let indexSpec = {
|
||||
"name": "TEST_IDX",
|
||||
"search_on": "none",
|
||||
"dataguide": "on"
|
||||
};
|
||||
if (isCreateIndexEnabled >= 0) {
|
||||
if (isCreateIndexEligible >= 0) {
|
||||
await collection.createIndex(indexSpec);
|
||||
let outDocument = await collection.getDataGuide();
|
||||
should.exist(outDocument);
|
||||
} else if(isCreateIndexEnabled < 0){
|
||||
} else if(isCreateIndexEligible < 0){
|
||||
await testsUtil.assertThrowsAsync(async () => {await collection.createIndex(indexSpec);}, /ORA-00406:/);
|
||||
}
|
||||
} catch(err) {
|
||||
should.not.exist(err);
|
||||
}
|
||||
if (isCreateIndexEnabled >= 0) {
|
||||
|
||||
if (isCreateIndexEligible >= 0) {
|
||||
try {
|
||||
let result = await collection.dropIndex('TEST_IDX');
|
||||
should.strictEqual(result.dropped, true);
|
||||
await conn.commit();
|
||||
await collection.drop();
|
||||
await conn.close();
|
||||
} catch(err) {
|
||||
should.not.exist(err);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (collection) await collection.drop();
|
||||
} catch (err) {
|
||||
should.not.exist(err);
|
||||
}
|
||||
try {
|
||||
if (conn) await conn.close();
|
||||
} catch (err) {
|
||||
should.not.exist(err);
|
||||
}
|
||||
|
||||
}); // 173.12
|
||||
|
||||
});
|
||||
|
|
|
@ -79,26 +79,3 @@ sodaUtil.t_contents = [
|
|||
{ id: 1006, name: "Joe", office: "San Francisco" },
|
||||
{ id: 1007, name: "Gavin", office: "New York" }
|
||||
];
|
||||
|
||||
|
||||
// Function versionStringCompare returns:
|
||||
// * 1 if version1 is greater than version2
|
||||
// * -1 if version1 is smaller than version2
|
||||
// * 0 if version1 is equal to version2
|
||||
// * undefined if eigher version1 or version2 is not string
|
||||
sodaUtil.versionStringCompare = function(version1, version2) {
|
||||
if (typeof version1 === 'string' && typeof version2 === 'string') {
|
||||
let tokens1 = version1.split('.');
|
||||
let tokens2 = version2.split('.');
|
||||
let len = Math.min(tokens1.length, tokens2.length);
|
||||
for (let i = 0; i < len; i++) {
|
||||
const t1 = parseInt(tokens1[i]), t2 = parseInt(tokens2[i]);
|
||||
if (t1 > t2) return 1;
|
||||
if (t1 < t2) return -1;
|
||||
}
|
||||
if (tokens1.length < tokens2.length) return 1;
|
||||
if (tokens1.length > tokens2.length) return -1;
|
||||
return 0;
|
||||
}
|
||||
return undefined;
|
||||
};
|
|
@ -30,6 +30,7 @@
|
|||
const oracledb = require('oracledb');
|
||||
const dbconfig = require('./dbconfig.js');
|
||||
const assert = require('assert');
|
||||
const should = require('should');
|
||||
|
||||
let testsUtil = exports;
|
||||
module.exports = testsUtil;
|
||||
|
@ -65,3 +66,48 @@ testsUtil.generateRandomPassword = function(length=6) {
|
|||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
testsUtil.getDBCompatibleVersion = async function() {
|
||||
let compatibleVersion;
|
||||
if (dbconfig.test.DBA_PRIVILEGE) {
|
||||
try {
|
||||
const connectionDetails = {
|
||||
user : dbconfig.test.DBA_user,
|
||||
password : dbconfig.test.DBA_password,
|
||||
connectString : dbconfig.connectString,
|
||||
privilege : oracledb.SYSDBA,
|
||||
};
|
||||
let conn = await oracledb.getConnection(connectionDetails);
|
||||
let res = await conn.execute("select name, value from v$parameter where name = 'compatible'");
|
||||
if(res.rows.length > 0) {
|
||||
compatibleVersion = res.rows[0][1];
|
||||
}
|
||||
await conn.close();
|
||||
} catch (err) {
|
||||
should.not.exist(err);
|
||||
}
|
||||
}
|
||||
return compatibleVersion;
|
||||
};
|
||||
|
||||
// Function versionStringCompare returns:
|
||||
// * 1 if version1 is greater than version2
|
||||
// * -1 if version1 is smaller than version2
|
||||
// * 0 if version1 is equal to version2
|
||||
// * undefined if eigher version1 or version2 is not string
|
||||
testsUtil.versionStringCompare = function(version1, version2) {
|
||||
if (typeof version1 === 'string' && typeof version2 === 'string') {
|
||||
let tokens1 = version1.split('.');
|
||||
let tokens2 = version2.split('.');
|
||||
let len = Math.min(tokens1.length, tokens2.length);
|
||||
for (let i = 0; i < len; i++) {
|
||||
const t1 = parseInt(tokens1[i]), t2 = parseInt(tokens2[i]);
|
||||
if (t1 > t2) return 1;
|
||||
if (t1 < t2) return -1;
|
||||
}
|
||||
if (tokens1.length < tokens2.length) return 1;
|
||||
if (tokens1.length > tokens2.length) return -1;
|
||||
return 0;
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue