Commit cf995ac0 authored by Alexandra Rogova's avatar Alexandra Rogova

added content size test scripts

parent 5bfa82fa
const os = require('os');
const puppeteer = require('puppeteer');
const si = require("systeminformation");
const Server = require('ws').Server;
const args = require("yargs")
.usage("Usage : load_content.js -saveAs metadata/attachment -file file_path")
.demandOption(['file'])
.demandOption(['saveAs'])
.alias("f", "file")
.alias("s", "saveAs")
.describe("file", "file containing content, data must follow the CSV standard")
.describe("saveAs", "choose whether to save the content as metadata or attachments in the indexeddb")
.nargs("file", 1)
.nargs("saveAs", 1)
.argv;
if (!(args.saveAs === "metadata" ||args.saveAs === "attachment")){
throw 'Unrecognized save as argument';
}
var saveAs = args.saveAs,
browser,
page,
ramBefore,
memBefore;
function init_server (){
var port = 9030;
var ws = new Server({port: port});
ws.on('connection', function(w){
w.on('message', function(msg){
console.log(msg);
var ramAfter = (os.totalmem() - os.freemem()) / 1024 / 1024;
var ramUsed = ramAfter - ramBefore;
console.log("Ram used : " + ramUsed + " MB");
si.mem(function(data){
console.log("Memory used : " + (data.used / 1024 / 1024 - memBefore) + " MB");
});
browser.close();
});
w.on('close', function() {
ws.close();
});
});
}
(async () => {
init_server();
browser = await puppeteer.launch();
page = await browser.newPage();
ramBefore = (os.totalmem() - os.freemem()) / 1024 / 1024;
si.mem(function(data){
memBefore = data.used / 1024 / 1024;
});
await page.goto('https://softinst115787.host.vifib.net/public/unit_tests/content_load.html?saveAs='+saveAs);
const [fileChooser] = await Promise.all([
page.waitForFileChooser(),
page.click('input#load')
]);
await fileChooser.accept([args.file]);
})();
const os = require('os');
const randomstring = require("randomstring");
const tmp = require('tmp');
const fs = require('fs');
const puppeteer = require('puppeteer');
const si = require("systeminformation");
const Server = require('ws').Server;
const args = require("yargs")
.usage("Usage : load_content_random.js -saveAs metadata/attachment -p Number of random paragraphs to generate")
.demandOption(['saveAs'])
.demandOption(['paragraphs'])
.alias("p", "paragraphs")
.alias("s", "saveAs")
.describe("paragraphs", "Number of random paragraphs to generate")
.describe("saveAs", "Choose whether to save the content as metadata or attachments in the indexeddb")
.nargs("saveAs", 1)
.nargs("paragraphs", 1)
.argv;
if (!(args.saveAs === "metadata" ||args.saveAs === "attachment")){
throw 'Unrecognized save as argument';
}
var saveAs = args.saveAs,
browser,
page,
ramBefore,
memBefore;
function gen_rdm_string (length){
return randomstring.generate({
length: length,
charset: 'alphabetic'
});
}
function gen_rdm_sentence (word_count, word_length){
var tmp_word_array = [];
for (var i = 0; i<word_count; i+=1){
tmp_word_array[i] = gen_rdm_string(word_length);
}
return tmp_word_array.join(" ");
}
function gen_rdm_paragraph (sentence_count, words_per_sentence, word_length){
var tmp_sentence_array = [];
for (var i=0; i<sentence_count; i+=1){
tmp_sentence_array[i] = gen_rdm_sentence(words_per_sentence, word_length);
}
return tmp_sentence_array.join(". ");
}
function init_server (){
var port = 9030;
var ws = new Server({port: port});
ws.on('connection', function(w){
w.on('message', function(msg){
console.log(msg);
var ramAfter = (os.totalmem() - os.freemem()) / 1024 / 1024;
var ramUsed = ramAfter - ramBefore;
console.log("Ram used : " + ramUsed + " MB");
si.mem(function(data){
console.log("Memory used : " + (data.used / 1024 / 1024 - memBefore) + " MB");
});
browser.close();
});
w.on('close', function() {
ws.close();
});
});
}
function gen_random_content (){
var tmp_para_array = [];
for(var i=0; i<args.p; i+=1){
tmp_para_array[i] = gen_rdm_paragraph(6, 15, 5);
}
var tmp_file = tmp.fileSync();
fs.writeFileSync(tmp_file.name, tmp_para_array.join("\n"));
return tmp_file.name;
}
(async () => {
init_server();
var file_path = gen_random_content();
browser = await puppeteer.launch();
page = await browser.newPage();
ramBefore = (os.totalmem() - os.freemem()) / 1024 / 1024;
si.mem(function(data){
memBefore = data.used / 1024 / 1024;
});
await page.goto('https://softinst115787.host.vifib.net/public/unit_tests/content_load.html?saveAs='+saveAs);
const [fileChooser] = await Promise.all([
page.waitForFileChooser(),
page.click('input#load')
]);
await fileChooser.accept([file_path]);
})();
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment