Merge pull request #151 from overleaf/msm-decaf-smoke-load

Decaffeinate smoke and load tests
This commit is contained in:
Miguel Serrano 2020-02-25 18:20:35 +01:00 committed by GitHub
commit 1997125b18
5 changed files with 203 additions and 135 deletions

View file

@ -1,71 +0,0 @@
request = require "request"
Settings = require "settings-sharelatex"
async = require("async")
fs = require("fs")
_ = require("underscore")
concurentCompiles = 5
totalCompiles = 50
buildUrl = (path) -> "http://#{Settings.internal.clsi.host}:#{Settings.internal.clsi.port}/#{path}"
mainTexContent = fs.readFileSync("./bulk.tex", "utf-8")
compileTimes = []
failedCount = 0
getAverageCompileTime = ->
totalTime = _.reduce compileTimes, (sum, time)->
sum + time
, 0
return totalTime / compileTimes.length
makeRequest = (compileNumber, callback)->
bulkBodyCount = 7
bodyContent = ""
while --bulkBodyCount
bodyContent = bodyContent+=mainTexContent
startTime = new Date()
request.post {
url: buildUrl("project/loadcompile-#{compileNumber}/compile")
json:
compile:
resources: [
path: "main.tex"
content: """
\\documentclass{article}
\\begin{document}
#{bodyContent}
\\end{document}
"""
]
}, (err, response, body)->
if response.statusCode != 200
failedCount++
return callback("compile #{compileNumber} failed")
if err?
failedCount++
return callback("failed")
totalTime = new Date() - startTime
console.log totalTime+"ms"
compileTimes.push(totalTime)
callback(err)
jobs = _.map [1..totalCompiles], (i)->
return (cb)->
makeRequest(i, cb)
startTime = new Date()
async.parallelLimit jobs, concurentCompiles, (err)->
if err?
console.error err
console.log("total time taken = #{(new Date() - startTime)/1000}s")
console.log("total compiles = #{totalCompiles}")
console.log("concurent compiles = #{concurentCompiles}")
console.log("average time = #{getAverageCompileTime()/1000}s")
console.log("max time = #{_.max(compileTimes)/1000}s")
console.log("min time = #{_.min(compileTimes)/1000}s")
console.log("total failures = #{failedCount}")

View file

@ -0,0 +1,103 @@
/* eslint-disable
standard/no-callback-literal,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
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
const buildUrl = path =>
`http://${Settings.internal.clsi.host}:${Settings.internal.clsi.port}/${path}`
const mainTexContent = fs.readFileSync('./bulk.tex', 'utf-8')
const compileTimes = []
let failedCount = 0
const getAverageCompileTime = function() {
const totalTime = _.reduce(compileTimes, (sum, time) => sum + time, 0)
return totalTime / compileTimes.length
}
const makeRequest = function(compileNumber, callback) {
let bulkBodyCount = 7
let bodyContent = ''
while (--bulkBodyCount) {
bodyContent = bodyContent += mainTexContent
}
const startTime = new Date()
return request.post(
{
url: buildUrl(`project/loadcompile-${compileNumber}/compile`),
json: {
compile: {
resources: [
{
path: 'main.tex',
content: `\
\\documentclass{article}
\\begin{document}
${bodyContent}
\\end{document}\
`
}
]
}
}
},
(err, response, body) => {
if (response.statusCode !== 200) {
failedCount++
return callback(`compile ${compileNumber} failed`)
}
if (err != null) {
failedCount++
return callback('failed')
}
const totalTime = new Date() - startTime
console.log(totalTime + 'ms')
compileTimes.push(totalTime)
return callback(err)
}
)
}
const jobs = _.map(__range__(1, totalCompiles, true), i => cb =>
makeRequest(i, cb)
)
const startTime = new Date()
async.parallelLimit(jobs, concurentCompiles, err => {
if (err != null) {
console.error(err)
}
console.log(`total time taken = ${(new Date() - startTime) / 1000}s`)
console.log(`total compiles = ${totalCompiles}`)
console.log(`concurent compiles = ${concurentCompiles}`)
console.log(`average time = ${getAverageCompileTime() / 1000}s`)
console.log(`max time = ${_.max(compileTimes) / 1000}s`)
console.log(`min time = ${_.min(compileTimes) / 1000}s`)
return console.log(`total failures = ${failedCount}`)
})
function __range__(left, right, inclusive) {
const range = []
const ascending = left < right
const 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
}

View file

@ -1,64 +0,0 @@
chai = require("chai")
chai.should() unless Object.prototype.should?
expect = chai.expect
request = require "request"
Settings = require "settings-sharelatex"
buildUrl = (path) -> "http://#{Settings.internal.clsi.host}:#{Settings.internal.clsi.port}/#{path}"
url = buildUrl("project/smoketest-#{process.pid}/compile")
describe "Running a compile", ->
before (done) ->
request.post {
url: url
json:
compile:
resources: [
path: "main.tex"
content: """
% Membrane-like surface
% Author: Yotam Avital
\\documentclass{article}
\\usepackage{tikz}
\\usetikzlibrary{calc,fadings,decorations.pathreplacing}
\\begin{document}
\\begin{tikzpicture}
\\def\\nuPi{3.1459265}
\\foreach \\i in {5,4,...,2}{% This one doesn't matter
\\foreach \\j in {3,2,...,0}{% This will crate a membrane
% with the front lipids visible
% top layer
\\pgfmathsetmacro{\\dx}{rand*0.1}% A random variance in the x coordinate
\\pgfmathsetmacro{\\dy}{rand*0.1}% A random variance in the y coordinate,
% gives a hight fill to the lipid
\\pgfmathsetmacro{\\rot}{rand*0.1}% A random variance in the
% molecule orientation
\\shade[ball color=red] ({\\i+\\dx+\\rot},{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)}) circle(0.45);
\\shade[ball color=gray] (\\i+\\dx,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-0.9}) circle(0.45);
\\shade[ball color=gray] (\\i+\\dx-\\rot,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-1.8}) circle(0.45);
% bottom layer
\\pgfmathsetmacro{\\dx}{rand*0.1}
\\pgfmathsetmacro{\\dy}{rand*0.1}
\\pgfmathsetmacro{\\rot}{rand*0.1}
\\shade[ball color=gray] (\\i+\\dx+\\rot,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-2.8}) circle(0.45);
\\shade[ball color=gray] (\\i+\\dx,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-3.7}) circle(0.45);
\\shade[ball color=red] (\\i+\\dx-\\rot,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-4.6}) circle(0.45);
}
}
\\end{tikzpicture}
\\end{document}
"""
]
}, (@error, @response, @body) =>
done()
it "should return the pdf", ->
for file in @body.compile.outputFiles
return if file.type == "pdf"
throw new Error("no pdf returned")
it "should return the log", ->
for file in @body.compile.outputFiles
return if file.type == "log"
throw new Error("no log returned")

View file

@ -0,0 +1,100 @@
/* eslint-disable
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const chai = require('chai')
if (Object.prototype.should == null) {
chai.should()
}
const { expect } = chai
const request = require('request')
const Settings = require('settings-sharelatex')
const buildUrl = path =>
`http://${Settings.internal.clsi.host}:${Settings.internal.clsi.port}/${path}`
const url = buildUrl(`project/smoketest-${process.pid}/compile`)
describe('Running a compile', function() {
before(function(done) {
return request.post(
{
url,
json: {
compile: {
resources: [
{
path: 'main.tex',
content: `\
% Membrane-like surface
% Author: Yotam Avital
\\documentclass{article}
\\usepackage{tikz}
\\usetikzlibrary{calc,fadings,decorations.pathreplacing}
\\begin{document}
\\begin{tikzpicture}
\\def\\nuPi{3.1459265}
\\foreach \\i in {5,4,...,2}{% This one doesn't matter
\\foreach \\j in {3,2,...,0}{% This will crate a membrane
% with the front lipids visible
% top layer
\\pgfmathsetmacro{\\dx}{rand*0.1}% A random variance in the x coordinate
\\pgfmathsetmacro{\\dy}{rand*0.1}% A random variance in the y coordinate,
% gives a hight fill to the lipid
\\pgfmathsetmacro{\\rot}{rand*0.1}% A random variance in the
% molecule orientation
\\shade[ball color=red] ({\\i+\\dx+\\rot},{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)}) circle(0.45);
\\shade[ball color=gray] (\\i+\\dx,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-0.9}) circle(0.45);
\\shade[ball color=gray] (\\i+\\dx-\\rot,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-1.8}) circle(0.45);
% bottom layer
\\pgfmathsetmacro{\\dx}{rand*0.1}
\\pgfmathsetmacro{\\dy}{rand*0.1}
\\pgfmathsetmacro{\\rot}{rand*0.1}
\\shade[ball color=gray] (\\i+\\dx+\\rot,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-2.8}) circle(0.45);
\\shade[ball color=gray] (\\i+\\dx,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-3.7}) circle(0.45);
\\shade[ball color=red] (\\i+\\dx-\\rot,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-4.6}) circle(0.45);
}
}
\\end{tikzpicture}
\\end{document}\
`
}
]
}
}
},
(error, response, body) => {
this.error = error
this.response = response
this.body = body
return done()
}
)
})
it('should return the pdf', function() {
for (const file of Array.from(this.body.compile.outputFiles)) {
if (file.type === 'pdf') {
return
}
}
throw new Error('no pdf returned')
})
return it('should return the log', function() {
for (const file of Array.from(this.body.compile.outputFiles)) {
if (file.type === 'log') {
return
}
}
throw new Error('no log returned')
})
})