Просмотр исходного кода

Merge pull request #8534 from overleaf/jpa-fix-downloads

[web] double down on passing compileBackendClass to clsi

GitOrigin-RevId: 6e035a885caa31e55ff0cf63c584f3f03629f1cf
Jakob Ackermann 4 лет назад
Родитель
Сommit
c999033eb4

+ 18 - 23
services/web/app/src/Features/Compile/CompileController.js

@@ -149,6 +149,7 @@ module.exports = CompileController = {
     }
     options.compileGroup =
       req.body?.compileGroup || Settings.defaultFeatures.compileGroup
+    options.compileBackendClass = Settings.apis.clsi.defaultBackendClass
     options.timeout =
       req.body?.timeout || Settings.defaultFeatures.compileTimeout
     ClsiManager.sendExternalRequest(
@@ -321,6 +322,7 @@ module.exports = CompileController = {
         req.body?.compileGroup ||
         req.query?.compileGroup ||
         Settings.defaultFeatures.compileGroup,
+      compileBackendClass: Settings.apis.clsi.defaultBackendClass,
     }
     CompileController.proxyToClsiWithLimits(
       submissionId,
@@ -419,33 +421,19 @@ module.exports = CompileController = {
   },
 
   proxyToClsi(projectId, url, req, res, next) {
-    if (req.query?.compileGroup) {
+    CompileManager.getProjectCompileLimits(projectId, function (error, limits) {
+      if (error) {
+        return next(error)
+      }
       CompileController.proxyToClsiWithLimits(
         projectId,
         url,
-        { compileGroup: req.query.compileGroup },
+        limits,
         req,
         res,
         next
       )
-    } else {
-      CompileManager.getProjectCompileLimits(
-        projectId,
-        function (error, limits) {
-          if (error) {
-            return next(error)
-          }
-          CompileController.proxyToClsiWithLimits(
-            projectId,
-            url,
-            limits,
-            req,
-            res,
-            next
-          )
-        }
-      )
-    }
+    })
   },
 
   proxyToClsiWithLimits(projectId, url, limits, req, res, next) {
@@ -453,6 +441,7 @@ module.exports = CompileController = {
       req,
       projectId,
       limits.compileGroup,
+      limits.compileBackendClass,
       (err, persistenceOptions) => {
         let qs
         if (err) {
@@ -529,18 +518,24 @@ module.exports = CompileController = {
   },
 }
 
-function _getPersistenceOptions(req, projectId, compileGroup, callback) {
+function _getPersistenceOptions(
+  req,
+  projectId,
+  compileGroup,
+  compileBackendClass,
+  callback
+) {
   const { clsiserverid } = req.query
   const userId = SessionManager.getLoggedInUserId(req)
   if (clsiserverid && typeof clsiserverid === 'string') {
-    callback(null, { qs: { clsiserverid, compileGroup } })
+    callback(null, { qs: { clsiserverid, compileGroup, compileBackendClass } })
   } else {
     ClsiCookieManager.getCookieJar(
       projectId,
       userId,
       compileGroup,
       (err, jar) => {
-        callback(err, { jar })
+        callback(err, { jar, qs: { compileGroup, compileBackendClass } })
       }
     )
   }

+ 76 - 39
services/web/test/unit/src/Compile/CompileControllerTests.js

@@ -24,6 +24,7 @@ describe('CompileController', function () {
       apis: {
         clsi: {
           url: 'clsi.example.com',
+          defaultBackendClass: 'e2',
         },
         clsi_priority: {
           url: 'clsi-priority.example.com',
@@ -280,13 +281,11 @@ describe('CompileController', function () {
       })
 
       it('should use the supplied values', function () {
-        this.ClsiManager.sendExternalRequest
-          .calledWith(
-            this.submission_id,
-            { compileGroup: 'special', timeout: 600 },
-            { compileGroup: 'special', timeout: 600 }
-          )
-          .should.equal(true)
+        this.ClsiManager.sendExternalRequest.should.have.been.calledWith(
+          this.submission_id,
+          { compileGroup: 'special', timeout: 600 },
+          { compileGroup: 'special', compileBackendClass: 'e2', timeout: 600 }
+        )
       })
     })
 
@@ -302,25 +301,24 @@ describe('CompileController', function () {
       })
 
       it('should use the other options but default values for compileGroup and timeout', function () {
-        this.ClsiManager.sendExternalRequest
-          .calledWith(
-            this.submission_id,
-            {
-              rootResourcePath: 'main.tex',
-              compiler: 'lualatex',
-              draft: true,
-              check: 'validate',
-            },
-            {
-              rootResourcePath: 'main.tex',
-              compiler: 'lualatex',
-              draft: true,
-              check: 'validate',
-              compileGroup: 'standard',
-              timeout: 60,
-            }
-          )
-          .should.equal(true)
+        this.ClsiManager.sendExternalRequest.should.have.been.calledWith(
+          this.submission_id,
+          {
+            rootResourcePath: 'main.tex',
+            compiler: 'lualatex',
+            draft: true,
+            check: 'validate',
+          },
+          {
+            rootResourcePath: 'main.tex',
+            compiler: 'lualatex',
+            draft: true,
+            check: 'validate',
+            compileGroup: 'standard',
+            compileBackendClass: 'e2',
+            timeout: 60,
+          }
+        )
       })
     })
   })
@@ -445,11 +443,14 @@ describe('CompileController', function () {
       })
 
       it('should proxy to CLSI with correct URL and default limits', function () {
-        this.CompileController.proxyToClsiWithLimits
-          .calledWith(this.submission_id, this.expected_url, {
+        this.CompileController.proxyToClsiWithLimits.should.have.been.calledWith(
+          this.submission_id,
+          this.expected_url,
+          {
             compileGroup: 'standard',
-          })
-          .should.equal(true)
+            compileBackendClass: 'e2',
+          }
+        )
       })
     })
 
@@ -464,11 +465,14 @@ describe('CompileController', function () {
       })
 
       it('should proxy to CLSI with correct URL and specified limits', function () {
-        this.CompileController.proxyToClsiWithLimits
-          .calledWith(this.submission_id, this.expected_url, {
+        this.CompileController.proxyToClsiWithLimits.should.have.been.calledWith(
+          this.submission_id,
+          this.expected_url,
+          {
             compileGroup: 'special',
-          })
-          .should.equal(true)
+            compileBackendClass: 'e2',
+          }
+        )
       })
     })
   })
@@ -566,7 +570,10 @@ describe('CompileController', function () {
         beforeEach(function () {
           this.CompileManager.getProjectCompileLimits = sinon
             .stub()
-            .callsArgWith(1, null, { compileGroup: 'standard' })
+            .callsArgWith(1, null, {
+              compileGroup: 'standard',
+              compileBackendClass: 'e2',
+            })
           this.CompileController.proxyToClsi(
             this.projectId,
             (this.url = '/test'),
@@ -580,6 +587,7 @@ describe('CompileController', function () {
           this.request
             .calledWith({
               jar: this.jar,
+              qs: { compileGroup: 'standard', compileBackendClass: 'e2' },
               method: this.req.method,
               url: `${this.settings.apis.clsi.url}${this.url}`,
               timeout: 60 * 1000,
@@ -614,6 +622,12 @@ describe('CompileController', function () {
       describe('user with standard priority via query string', function () {
         beforeEach(function () {
           this.req.query = { compileGroup: 'standard' }
+          this.CompileManager.getProjectCompileLimits = sinon
+            .stub()
+            .callsArgWith(1, null, {
+              compileGroup: 'standard',
+              compileBackendClass: 'e2',
+            })
           this.CompileController.proxyToClsi(
             this.projectId,
             (this.url = '/test'),
@@ -627,6 +641,7 @@ describe('CompileController', function () {
           this.request
             .calledWith({
               jar: this.jar,
+              qs: { compileGroup: 'standard', compileBackendClass: 'e2' },
               method: this.req.method,
               url: `${this.settings.apis.clsi.url}${this.url}`,
               timeout: 60 * 1000,
@@ -646,6 +661,12 @@ describe('CompileController', function () {
       describe('user with non-existent priority via query string', function () {
         beforeEach(function () {
           this.req.query = { compileGroup: 'foobar' }
+          this.CompileManager.getProjectCompileLimits = sinon
+            .stub()
+            .callsArgWith(1, null, {
+              compileGroup: 'standard',
+              compileBackendClass: 'e2',
+            })
           this.CompileController.proxyToClsi(
             this.projectId,
             (this.url = '/test'),
@@ -659,6 +680,7 @@ describe('CompileController', function () {
           this.request
             .calledWith({
               jar: this.jar,
+              qs: { compileGroup: 'standard', compileBackendClass: 'e2' },
               method: this.req.method,
               url: `${this.settings.apis.clsi.url}${this.url}`,
               timeout: 60 * 1000,
@@ -671,7 +693,10 @@ describe('CompileController', function () {
         beforeEach(function () {
           this.CompileManager.getProjectCompileLimits = sinon
             .stub()
-            .callsArgWith(1, null, { compileGroup: 'standard' })
+            .callsArgWith(1, null, {
+              compileGroup: 'standard',
+              compileBackendClass: 'e2',
+            })
           this.req.query = { build: 1234 }
           this.CompileController.proxyToClsi(
             this.projectId,
@@ -686,6 +711,7 @@ describe('CompileController', function () {
           this.request
             .calledWith({
               jar: this.jar,
+              qs: { compileGroup: 'standard', compileBackendClass: 'e2' },
               method: this.req.method,
               url: `${this.settings.apis.clsi.url}${this.url}`,
               timeout: 60 * 1000,
@@ -703,7 +729,10 @@ describe('CompileController', function () {
         beforeEach(function () {
           this.CompileManager.getProjectCompileLimits = sinon
             .stub()
-            .callsArgWith(1, null, { compileGroup: 'standard' })
+            .callsArgWith(1, null, {
+              compileGroup: 'standard',
+              compileBackendClass: 'e2',
+            })
           this.CompileController.proxyToClsi(
             this.projectId,
             (this.url = '/test'),
@@ -717,6 +746,7 @@ describe('CompileController', function () {
           this.request
             .calledWith({
               jar: this.jar,
+              qs: { compileGroup: 'standard', compileBackendClass: 'e2' },
               method: this.req.method,
               url: `${this.settings.apis.clsi.url}${this.url}`,
               timeout: 60 * 1000,
@@ -742,7 +772,10 @@ describe('CompileController', function () {
         beforeEach(function () {
           this.CompileManager.getProjectCompileLimits = sinon
             .stub()
-            .callsArgWith(1, null, { compileGroup: 'standard' })
+            .callsArgWith(1, null, {
+              compileGroup: 'standard',
+              compileBackendClass: 'e2',
+            })
           this.req.query = { build: 1234, pdfng: true }
           this.CompileController.proxyToClsi(
             this.projectId,
@@ -758,7 +791,11 @@ describe('CompileController', function () {
             .calledWith({
               jar: this.jar,
               method: this.req.method,
-              qs: { build: 1234 },
+              qs: {
+                build: 1234,
+                compileGroup: 'standard',
+                compileBackendClass: 'e2',
+              },
               url: `${this.settings.apis.clsi.url}${this.url}`,
               timeout: 60 * 1000,
               headers: {