SmokeTests.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. const request = require('request')
  2. const Settings = require('@overleaf/settings')
  3. const buildUrl = path =>
  4. `http://${Settings.internal.clsi.host}:${Settings.internal.clsi.port}/${path}`
  5. const url = buildUrl(`project/smoketest-${process.pid}/compile`)
  6. module.exports = {
  7. sendNewResult(res) {
  8. this._run(error => this._sendResponse(res, error))
  9. },
  10. sendLastResult(res) {
  11. this._sendResponse(res, this._lastError)
  12. },
  13. triggerRun(cb) {
  14. this._run(error => {
  15. this._lastError = error
  16. cb(error)
  17. })
  18. },
  19. lastRunSuccessful() {
  20. return this._lastError == null
  21. },
  22. _lastError: new Error('SmokeTestsPending'),
  23. _sendResponse(res, error) {
  24. let code, body
  25. if (error) {
  26. code = 500
  27. body = error.message
  28. } else {
  29. code = 200
  30. body = 'OK'
  31. }
  32. res.contentType('text/plain')
  33. res.status(code).send(body)
  34. },
  35. _run(done) {
  36. request.post(
  37. {
  38. url,
  39. json: {
  40. compile: {
  41. options: {
  42. metricsPath: 'health-check',
  43. },
  44. resources: [
  45. {
  46. path: 'main.tex',
  47. content: `\
  48. % Membrane-like surface
  49. % Author: Yotam Avital
  50. \\documentclass{article}
  51. \\usepackage{tikz}
  52. \\usetikzlibrary{calc,fadings,decorations.pathreplacing}
  53. \\begin{document}
  54. \\begin{tikzpicture}
  55. \\def\\nuPi{3.1459265}
  56. \\foreach \\i in {5,4,...,2}{% This one doesn't matter
  57. \\foreach \\j in {3,2,...,0}{% This will crate a membrane
  58. % with the front lipids visible
  59. % top layer
  60. \\pgfmathsetmacro{\\dx}{rand*0.1}% A random variance in the x coordinate
  61. \\pgfmathsetmacro{\\dy}{rand*0.1}% A random variance in the y coordinate,
  62. % gives a hight fill to the lipid
  63. \\pgfmathsetmacro{\\rot}{rand*0.1}% A random variance in the
  64. % molecule orientation
  65. \\shade[ball color=red] ({\\i+\\dx+\\rot},{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)}) circle(0.45);
  66. \\shade[ball color=gray] (\\i+\\dx,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-0.9}) circle(0.45);
  67. \\shade[ball color=gray] (\\i+\\dx-\\rot,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-1.8}) circle(0.45);
  68. % bottom layer
  69. \\pgfmathsetmacro{\\dx}{rand*0.1}
  70. \\pgfmathsetmacro{\\dy}{rand*0.1}
  71. \\pgfmathsetmacro{\\rot}{rand*0.1}
  72. \\shade[ball color=gray] (\\i+\\dx+\\rot,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-2.8}) circle(0.45);
  73. \\shade[ball color=gray] (\\i+\\dx,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-3.7}) circle(0.45);
  74. \\shade[ball color=red] (\\i+\\dx-\\rot,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-4.6}) circle(0.45);
  75. }
  76. }
  77. \\end{tikzpicture}
  78. \\end{document}\
  79. `,
  80. },
  81. ],
  82. },
  83. },
  84. },
  85. (error, response, body) => {
  86. if (error) return done(error)
  87. if (!body || !body.compile || !body.compile.outputFiles) {
  88. return done(new Error('response payload incomplete'))
  89. }
  90. let pdfFound = false
  91. let logFound = false
  92. for (const file of body.compile.outputFiles) {
  93. if (file.type === 'pdf') pdfFound = true
  94. if (file.type === 'log') logFound = true
  95. }
  96. if (!pdfFound) return done(new Error('no pdf returned'))
  97. if (!logFound) return done(new Error('no log returned'))
  98. done()
  99. }
  100. )
  101. },
  102. }