SmokeTests.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import request from 'request'
  2. import Settings from '@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. export default {
  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. \\usepackage{ifplatform} % test shell escape, conditionals to test which platform is being used
  54. \\usepackage{minted} % to test shell commands
  55. \\usepackage{bashful} % to test shell commands
  56. \\begin{document}
  57. \\begin{tikzpicture}
  58. \\def\\nuPi{3.1459265}
  59. \\foreach \\i in {5,4,...,2}{% This one doesn't matter
  60. \\foreach \\j in {3,2,...,0}{% This will crate a membrane
  61. % with the front lipids visible
  62. % top layer
  63. \\pgfmathsetmacro{\\dx}{rand*0.1}% A random variance in the x coordinate
  64. \\pgfmathsetmacro{\\dy}{rand*0.1}% A random variance in the y coordinate,
  65. % gives a hight fill to the lipid
  66. \\pgfmathsetmacro{\\rot}{rand*0.1}% A random variance in the
  67. % molecule orientation
  68. \\shade[ball color=red] ({\\i+\\dx+\\rot},{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)}) circle(0.45);
  69. \\shade[ball color=gray] (\\i+\\dx,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-0.9}) circle(0.45);
  70. \\shade[ball color=gray] (\\i+\\dx-\\rot,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-1.8}) circle(0.45);
  71. % bottom layer
  72. \\pgfmathsetmacro{\\dx}{rand*0.1}
  73. \\pgfmathsetmacro{\\dy}{rand*0.1}
  74. \\pgfmathsetmacro{\\rot}{rand*0.1}
  75. \\shade[ball color=gray] (\\i+\\dx+\\rot,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-2.8}) circle(0.45);
  76. \\shade[ball color=gray] (\\i+\\dx,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-3.7}) circle(0.45);
  77. \\shade[ball color=red] (\\i+\\dx-\\rot,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-4.6}) circle(0.45);
  78. }
  79. }
  80. \\end{tikzpicture}
  81. % Test minted (shell commands)
  82. \\begin{minted}{python}
  83. x = 1 + 2
  84. \\end{minted}
  85. % Test bashful (shell commands)
  86. \\bash[stdout,stderr]
  87. date
  88. \\END
  89. % Test system
  90. \\immediate\\write18{/bin/date > date.txt}
  91. \\input date.txt
  92. % Test popen
  93. \\input{"|date"}
  94. \\end{document}\
  95. `,
  96. },
  97. ],
  98. },
  99. },
  100. },
  101. (error, response, body) => {
  102. if (error) return done(error)
  103. if (!body || !body.compile || !body.compile.outputFiles) {
  104. return done(new Error('response payload incomplete'))
  105. }
  106. let pdfFound = false
  107. let logFound = false
  108. for (const file of body.compile.outputFiles) {
  109. if (file.type === 'pdf') pdfFound = true
  110. if (file.type === 'log') logFound = true
  111. }
  112. if (!pdfFound) return done(new Error('no pdf returned'))
  113. if (!logFound) return done(new Error('no log returned'))
  114. done()
  115. }
  116. )
  117. },
  118. }