SmokeTests.js 3.2 KB

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