StopCompile.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { promisify } from 'node:util'
  2. import Client from './helpers/Client.js'
  3. import ClsiApp from './helpers/ClsiApp.js'
  4. import { expect } from 'chai'
  5. const sleep = promisify(setTimeout)
  6. describe('Stop compile', function () {
  7. before(async function () {
  8. this.request = {
  9. options: {
  10. timeout: 100,
  11. }, // seconds
  12. resources: [
  13. {
  14. path: 'main.tex',
  15. content: `\
  16. \\documentclass{article}
  17. \\begin{document}
  18. \\def\\x{Hello!\\par\\x}
  19. \\x
  20. \\end{document}\
  21. `,
  22. },
  23. ],
  24. }
  25. this.project_id = Client.randomId()
  26. await ClsiApp.ensureRunning()
  27. // start the compile in the background
  28. Client.compile(this.project_id, this.request)
  29. .then(body => {
  30. this.compileResult = { body }
  31. })
  32. .catch(error => {
  33. this.compileResult = { error }
  34. })
  35. // wait for 1 second before stopping the compile
  36. await sleep(1000)
  37. try {
  38. const res = await Client.stopCompile(this.project_id)
  39. this.stopResult = { res }
  40. } catch (error) {
  41. this.stopResult = { error }
  42. }
  43. // allow time for the compile request to terminate
  44. await sleep(1000)
  45. })
  46. it('should force a compile response with an error status', function () {
  47. expect(this.stopResult.error).not.to.exist
  48. expect(this.stopResult.res.status).to.equal(204)
  49. expect(this.compileResult.error).not.to.exist
  50. expect(this.compileResult.body.compile.status).to.equal('terminated')
  51. expect(this.compileResult.body.compile.error).to.equal('terminated')
  52. })
  53. })