jchaos
Version:
module to access chaos resources
338 lines (267 loc) • 9.55 kB
JavaScript
var assert = require('assert');
//var assert = require('chai').assert;
var jchaos = require('jchaos');
const fs = require('fs');
options = {};
var mincu = 40
process.argv.forEach(function (val, index, array) {
if (val == "uri") {
options.uri = array[index + 1];
console.log(val + "=" + array[index + 1]);
}
if (val == "async") {
options.async = (array[index + 1] == "true");
console.log(val + "=" + array[index + 1]);
}
if (val == "npush") {
npush = (array[index + 1]);
console.log(val + "=" + array[index + 1]);
}
});
var cualive = [];
var status_to_check = ["Start", "Stop", "Init", "Deinit", "Fatal Error", "Recoverable Error"];
var cualive_by_status = [];
var cualive_ds = [];
var cu_all = [];
var class_alive = [];
var class_all = [];
var zone_alive = [];
var zone_all = [];
jchaos.setOptions(options);
describe("CHAOS LIVE TESTS", function () {
this.timeout(1200000);
describe('SEARCH', function () {
it('Delete Test Nodes (if any)', function (done) {
var elen = 0;
jchaos.search("PERFORMANCE_IO", "cu", false, function (data) {
if (data.length == 0) {
console.log("\tNo test nodes to remove");
done(0);
}
data.forEach(function (ele) {
jchaos.node(ele, "deletenode", "cu", function () {
elen++;
console.log("\tremoved " + ele + " " + elen + "/" + data.length);
if (elen == data.length) {
done(0);
}
}, function (err) {
console.error("## removing node " + ele + " error:" + JSON.stringify(err));
done(1);
});
});
}, function (err) {
console.error("## searching, error:" + JSON.stringify(err));
done(1);
});
});
it('SEARCH ALL CU', function (done) {
jchaos.checkPeriodiocally("Check more than " + mincu, 30, 2000, function (t,okk,badd) {
cu_all=jchaos.search("", "cu", false);
if(cu_all instanceof Array){
if((cu_all.length>mincu)){
console.log("\t"+jchaos.getISOTimeFromChannel() +" "+" found :"+cu_all.length)
return true;
} else {
console.log("\t"+jchaos.getISOTimeFromChannel() +" "+" found :"+cu_all.length +" must be >"+mincu)
return false;
}
}
}, (ok) => { done(0); }, (bad) => { done(1) });
});
it('SEARCH ALIVE CU', function (done) {
jchaos.checkPeriodiocally("Check alive for more than " + mincu, 30, 2000, function (t,okk,badd) {
cualive=jchaos.search("", "cu", true);
if(cualive instanceof Array){
if((cualive.length>mincu)){
console.log("\t"+jchaos.getISOTimeFromChannel() +" "+" found :"+cualive.length)
return true;
} else {
console.log("\t"+jchaos.getISOTimeFromChannel() +" "+" found :"+cualive.length +" must be >"+mincu)
return false;
}
}
}, (ok) => { done(0); }, (bad) => { done(1) });
});
it('SEARCH CLASS ALIVE array not null array of names', function (done) {
jchaos.search("", "class", true, function (data) {
class_alive = data;
done(class_alive.length <= 0);
},(bad)=>{
console.log("Error performing search class:"+JSON.stringify(bad));
done(1);
});
})
it('SEARCH ZONE ALIVE array not null array of names', function (done) {
jchaos.search("", "zone", true, function (data) {
zone_alive = data;
done((zone_alive.length <= 0));
},(bad)=>{
done(1);
console.log("Error performing search zone:"+JSON.stringify(bad));
});
})
it('SEARCH ZONE ALL array not null array of names', function (done) {
jchaos.search("", "zone", false, function (data) {
zone_all = data;
done(zone_all.length <= 0);
});
})
after(function () {
console.log("\tALIVE CU :" + cualive.length);
console.log("\tALL CU :" + cu_all.length);
console.log("\tALIVE CLASSES :" + class_alive);
console.log("\tALIVE ZONE :" + zone_alive);
});
});
function checkFinish(done) {
if (ndone > 0)
done();
}
describe('LIVE TEST', function () {
this.timeout(1200000);
var cu_in_start = [];
// make it on started CU
it('RETRIVE CU IN START', function (done) {
jchaos.checkLive('\tWaiting for ALL start', cualive, 30, 2000, function (ds, nok, listok) {
if (ds.health !== undefined) {
if (ds.health.hasOwnProperty("nh_status"))
if ((ds.health.nh_status == "Start")) {
cu_in_start = listok;
return true;
} else {
console.log(ds.health.ndk_uid + " :" + ds.health.nh_status);
}
}
return false;
}, (ok) => { done(0); }, (bad) => { done(1); });
});
it('Test all datasets', function (done) {
jchaos.checkLive('\tLive check', cu_in_start, 60, 2000, function (ds) {
var ret = false;
// console.log("syslen:"+JSON.stringify(ds.system).length+ " healt len:"+JSON.stringify(ds.health).length+" outlen:"+JSON.stringify(ds.output).length);
if (typeof (JSON.stringify(ds.system)) == 'undefined') {
console.log(ds.health.ndk_uid, ": SYSTEM Undefined");
fs.appendFile('test-live.err', "SYSTEM Undefined:"+JSON.stringify(ds)+"\n", function (err) {
});
}
if (typeof (JSON.stringify(ds.health)) == 'undefined') {
console.log(ds.system.ndk_uid, ": HEALTH Undefined");
fs.appendFile('test-live.err', "HEALTH Undefined:"+JSON.stringify(ds)+"\n", function (err) {
});
}
if (typeof (JSON.stringify(ds.output)) == 'undefined') {
console.log(ds.health.ndk_uid, ": OUTPUT Undefined");
fs.appendFile('test-live.err', "OUTPUT Undefined:"+JSON.stringify(ds)+"\n", function (err) {
});
}
try {
ret = ((JSON.stringify(ds.system).length >= 2) && (JSON.stringify(ds.health).length >= 2) && (JSON.stringify(ds.output).length >= 2));
} catch (err) {
}
return ret;
}, function () { done(0); }, function () { done(1); });
});
it('GET FULL LIVE STATUS', function (done) {
jchaos.getChannel(cualive, -1, function (ll) {
cualive_ds = ll;
var check = JSON.stringify(cualive_ds);
done(!((check.length >= 2) && (cualive_ds.length == cualive.length)));
});
});
describe('Bypass Test', function () {
it('Check for bypass key', function (done) {
this.timeout(2400000);
jchaos.checkLive('\tCheck bypass key', cu_in_start, 30, 2000, function (elem) {
var ret = false;
if (elem.hasOwnProperty('system') && elem.hasOwnProperty('health')) {
if (elem.system.hasOwnProperty('cudk_bypass_state') == false) {
console.log("\tmissing bypass key in \"" + JSON.stringify(elem.health.ndk_uid) + "\" all:" + JSON.stringify(elem.system));
return false;
}
return true;
}
return false;
}, function () { done(0); }, function () { done(1); });
});
/*
it('bypass command set TRUE', function (done) {
this.timeout(2400000);
// make it on started CU
var num = 0;
jchaos.setBypass(cu_in_start, true, function (d) {
done(false);
});
});
it('Check for bypass command set TRUE', function (done) {
this.timeout(60000);
jchaos.checkLive('\tCheck for bypass command set TRUE', cu_in_start, 30, 2000, function (ds) { return (ds.system.cudk_bypass_state == true); }, function () { done(0); }, function () { done(1); });
});
it('bypass command set FALSE', function (done) {
this.timeout(60000);
// make it on started CU
var num = 0;
jchaos.setBypass(cu_in_start, false, function (d) {
done(false);
});
});
it('Check for bypass command set FALSE', function (done) {
this.timeout(60000);
jchaos.checkLive('\tCheck for bypass command set FALSE', cu_in_start, 30, 2000, function (ds) { return (ds.system.cudk_bypass_state == false); }, function () { done(0); }, function () { done(1); });
});*/
});
it('Check for health updates every 5s', function (done) {
this.timeout(2400000);
// make it on started CU
var cu_in_start = [];
jchaos.getCUStatus("Start", function (ll) {
cu_in_start = ll;
cu_timestamp = [];
cu_new_timestamp = [];
// console.log("\t ["+elem+"] set bypass false");
jchaos.getChannel(cu_in_start, 4, function (data) {
//console.log("\t ["+cu_in_start+"] :"+JSON.stringify(data));
data.forEach(function (elem) {
// console.log("\t ->"+Number(elem.nh_ts)+ " string:"+elem.nh_ts);
cu_timestamp.push(Number(elem.nh_ts));
});
});
});
setTimeout(function () {
var some_error = 0;
jchaos.getChannel(cu_in_start, 4, function (data) {
data.forEach(function (elem) {
cu_new_timestamp.push(Number(elem.nh_ts));
});
for (var i = 0; i < cu_new_timestamp.length; i++) {
if (cu_new_timestamp[i] - cu_timestamp[i] < 5000) {
console.error("\t difference " + cu_new_timestamp[i] + " - " + cu_timestamp[i] + " < 5000");
some_error++;
} else {
// console.log("\t difference "+(cu_new_timestamp[i] - cu_timestamp[i]));
}
}
done(some_error);
});
}, 10000);
});
});
describe('Logging Test', function () {
it('Search all logs', function (done) {
jchaos.log(cualive, "search", "all", 0, 10000000000000, function (data) {
var cnt = 0
if (data.hasOwnProperty("result_list")) {
var arr = data.result_list;
arr.forEach(function (item) {
//console.log("data:" +JSON.stringify(item));
if (item.hasOwnProperty("mdsndk_nl_sid")) {
cnt++;
//console.log(" counter:"+cnt+" expected:"+arr.length+" json:"+JSON.stringify(item));
}
});
done((cnt != arr.length));
}
});
});
});
});