decaffeinate: Convert loadTest.coffee to JS

This commit is contained in:
decaffeinate 2020-02-25 17:03:57 +01:00 committed by mserranom
parent e20da38e09
commit 3901fe9cd2

View file

@ -1,71 +1,97 @@
request = require "request" /*
Settings = require "settings-sharelatex" * decaffeinate suggestions:
async = require("async") * DS102: Remove unnecessary code created because of implicit returns
fs = require("fs") * DS207: Consider shorter variations of null checks
_ = require("underscore") * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
concurentCompiles = 5 */
totalCompiles = 50 const request = require("request");
const Settings = require("settings-sharelatex");
const async = require("async");
const fs = require("fs");
const _ = require("underscore");
const concurentCompiles = 5;
const totalCompiles = 50;
buildUrl = (path) -> "http://#{Settings.internal.clsi.host}:#{Settings.internal.clsi.port}/#{path}" const buildUrl = path => `http://${Settings.internal.clsi.host}:${Settings.internal.clsi.port}/${path}`;
mainTexContent = fs.readFileSync("./bulk.tex", "utf-8") const mainTexContent = fs.readFileSync("./bulk.tex", "utf-8");
compileTimes = [] const compileTimes = [];
failedCount = 0 let failedCount = 0;
getAverageCompileTime = -> const getAverageCompileTime = function() {
totalTime = _.reduce compileTimes, (sum, time)-> const totalTime = _.reduce(compileTimes, (sum, time)=> sum + time
sum + time , 0);
, 0 return totalTime / compileTimes.length;
return totalTime / compileTimes.length };
makeRequest = (compileNumber, callback)-> const makeRequest = function(compileNumber, callback){
bulkBodyCount = 7 let bulkBodyCount = 7;
bodyContent = "" let bodyContent = "";
while --bulkBodyCount while (--bulkBodyCount) {
bodyContent = bodyContent+=mainTexContent bodyContent = (bodyContent+=mainTexContent);
}
startTime = new Date() const startTime = new Date();
request.post { return request.post({
url: buildUrl("project/loadcompile-#{compileNumber}/compile") url: buildUrl(`project/loadcompile-${compileNumber}/compile`),
json: json: {
compile: compile: {
resources: [ resources: [{
path: "main.tex" path: "main.tex",
content: """ content: `\
\\documentclass{article} \\documentclass{article}
\\begin{document} \\begin{document}
#{bodyContent} ${bodyContent}
\\end{document} \\end{document}\
""" `
}
] ]
}, (err, response, body)-> }
if response.statusCode != 200 }
failedCount++ }, function(err, response, body){
return callback("compile #{compileNumber} failed") if (response.statusCode !== 200) {
if err? failedCount++;
failedCount++ return callback(`compile ${compileNumber} failed`);
return callback("failed") }
totalTime = new Date() - startTime if (err != null) {
console.log totalTime+"ms" failedCount++;
compileTimes.push(totalTime) return callback("failed");
callback(err) }
const totalTime = new Date() - startTime;
console.log(totalTime+"ms");
compileTimes.push(totalTime);
return callback(err);
});
};
jobs = _.map [1..totalCompiles], (i)-> const jobs = _.map(__range__(1, totalCompiles, true), i=>
return (cb)-> cb=> makeRequest(i, cb)
makeRequest(i, cb) );
startTime = new Date() const startTime = new Date();
async.parallelLimit jobs, concurentCompiles, (err)-> async.parallelLimit(jobs, concurentCompiles, function(err){
if err? if (err != null) {
console.error err console.error(err);
console.log("total time taken = #{(new Date() - startTime)/1000}s") }
console.log("total compiles = #{totalCompiles}") console.log(`total time taken = ${(new Date() - startTime)/1000}s`);
console.log("concurent compiles = #{concurentCompiles}") console.log(`total compiles = ${totalCompiles}`);
console.log("average time = #{getAverageCompileTime()/1000}s") console.log(`concurent compiles = ${concurentCompiles}`);
console.log("max time = #{_.max(compileTimes)/1000}s") console.log(`average time = ${getAverageCompileTime()/1000}s`);
console.log("min time = #{_.min(compileTimes)/1000}s") console.log(`max time = ${_.max(compileTimes)/1000}s`);
console.log("total failures = #{failedCount}") console.log(`min time = ${_.min(compileTimes)/1000}s`);
return console.log(`total failures = ${failedCount}`);
});
function __range__(left, right, inclusive) {
let range = [];
let ascending = left < right;
let end = !inclusive ? right : ascending ? right + 1 : right - 1;
for (let i = left; ascending ? i < end : i > end; ascending ? i++ : i--) {
range.push(i);
}
return range;
}