SmokeTests.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import { fetchJson } from '@overleaf/fetch-utils'
  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. async sendNewResult(res) {
  8. let error
  9. try {
  10. await this._run()
  11. } catch (err) {
  12. error = err
  13. }
  14. this._sendResponse(res, error)
  15. },
  16. sendLastResult(res) {
  17. this._sendResponse(res, this._lastError)
  18. },
  19. triggerRun(cb) {
  20. this._run()
  21. .then(() => {
  22. this._lastError = null
  23. cb()
  24. })
  25. .catch(error => {
  26. this._lastError = error
  27. cb(error)
  28. })
  29. },
  30. lastRunSuccessful() {
  31. return this._lastError == null
  32. },
  33. _lastError: new Error('SmokeTestsPending'),
  34. _sendResponse(res, error) {
  35. let code, body
  36. if (error) {
  37. code = 500
  38. body = error.message
  39. } else {
  40. code = 200
  41. body = 'OK'
  42. }
  43. res.contentType('text/plain')
  44. res.status(code).send(body)
  45. },
  46. async _run() {
  47. const body = await fetchJson(url, {
  48. method: 'POST',
  49. json: {
  50. compile: {
  51. options: {
  52. metricsPath: 'health-check',
  53. },
  54. resources: [
  55. {
  56. path: 'main.tex',
  57. content: `\
  58. % Membrane-like surface
  59. % Author: Yotam Avital
  60. \\documentclass{article}
  61. \\usepackage{tikz}
  62. \\usetikzlibrary{calc,fadings,decorations.pathreplacing}
  63. \\usepackage{ifplatform} % test shell escape, conditionals to test which platform is being used
  64. \\usepackage{minted} % to test shell commands
  65. \\usepackage{bashful} % to test shell commands
  66. \\begin{document}
  67. \\begin{tikzpicture}
  68. \\def\\nuPi{3.1459265}
  69. \\foreach \\i in {5,4,...,2}{% This one doesn't matter
  70. \\foreach \\j in {3,2,...,0}{% This will crate a membrane
  71. % with the front lipids visible
  72. % top layer
  73. \\pgfmathsetmacro{\\dx}{rand*0.1}% A random variance in the x coordinate
  74. \\pgfmathsetmacro{\\dy}{rand*0.1}% A random variance in the y coordinate,
  75. % gives a hight fill to the lipid
  76. \\pgfmathsetmacro{\\rot}{rand*0.1}% A random variance in the
  77. % molecule orientation
  78. \\shade[ball color=red] ({\\i+\\dx+\\rot},{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)}) circle(0.45);
  79. \\shade[ball color=gray] (\\i+\\dx,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-0.9}) circle(0.45);
  80. \\shade[ball color=gray] (\\i+\\dx-\\rot,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-1.8}) circle(0.45);
  81. % bottom layer
  82. \\pgfmathsetmacro{\\dx}{rand*0.1}
  83. \\pgfmathsetmacro{\\dy}{rand*0.1}
  84. \\pgfmathsetmacro{\\rot}{rand*0.1}
  85. \\shade[ball color=gray] (\\i+\\dx+\\rot,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-2.8}) circle(0.45);
  86. \\shade[ball color=gray] (\\i+\\dx,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-3.7}) circle(0.45);
  87. \\shade[ball color=red] (\\i+\\dx-\\rot,{0.5*\\j+\\dy+0.4*sin(\\i*\\nuPi*10)-4.6}) circle(0.45);
  88. }
  89. }
  90. \\end{tikzpicture}
  91. % Test minted (shell commands)
  92. \\begin{minted}{python}
  93. x = 1 + 2
  94. \\end{minted}
  95. % Test bashful (shell commands)
  96. \\bash[stdout,stderr]
  97. date
  98. \\END
  99. % Test system
  100. \\immediate\\write18{/bin/date > date.txt}
  101. \\input date.txt
  102. % Test popen
  103. \\input{"|date"}
  104. \\end{document}\
  105. `,
  106. },
  107. ],
  108. },
  109. },
  110. })
  111. if (!body || !body.compile || !body.compile.outputFiles) {
  112. throw new Error('response payload incomplete')
  113. }
  114. let pdfFound = false
  115. let logFound = false
  116. for (const file of body.compile.outputFiles) {
  117. if (file.type === 'pdf') pdfFound = true
  118. if (file.type === 'log') logFound = true
  119. }
  120. if (!pdfFound) throw new Error('no pdf returned')
  121. if (!logFound) throw new Error('no log returned')
  122. },
  123. }