|
@@ -10,11 +10,8 @@ describe "CompileManager", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
@rateLimitGetStub = sinon.stub()
|
|
@rateLimitGetStub = sinon.stub()
|
|
|
rateLimitGetStub = @rateLimitGetStub
|
|
rateLimitGetStub = @rateLimitGetStub
|
|
|
- @ratelimiter = class RateLimiter
|
|
|
|
|
- constructor: ->
|
|
|
|
|
- return {
|
|
|
|
|
- get: rateLimitGetStub
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ @ratelimiter =
|
|
|
|
|
+ addCount: sinon.stub()
|
|
|
@CompileManager = SandboxedModule.require modulePath, requires:
|
|
@CompileManager = SandboxedModule.require modulePath, requires:
|
|
|
"settings-sharelatex": @settings =
|
|
"settings-sharelatex": @settings =
|
|
|
redis: web: {host: "localhost", port: 42}
|
|
redis: web: {host: "localhost", port: 42}
|
|
@@ -25,7 +22,7 @@ describe "CompileManager", ->
|
|
|
"../../models/Project": Project: @Project = {}
|
|
"../../models/Project": Project: @Project = {}
|
|
|
"./ClsiManager": @ClsiManager = {}
|
|
"./ClsiManager": @ClsiManager = {}
|
|
|
"../../managers/LatexManager": @LatexManager = {}
|
|
"../../managers/LatexManager": @LatexManager = {}
|
|
|
- "ratelimiter":@ratelimiter
|
|
|
|
|
|
|
+ "../../infrastructure/RateLimiter": @ratelimiter
|
|
|
"../../infrastructure/Metrics": @Metrics =
|
|
"../../infrastructure/Metrics": @Metrics =
|
|
|
Timer: class Timer
|
|
Timer: class Timer
|
|
|
done: sinon.stub()
|
|
done: sinon.stub()
|
|
@@ -53,7 +50,6 @@ describe "CompileManager", ->
|
|
|
.calledWith(@project_id, @user_id)
|
|
.calledWith(@project_id, @user_id)
|
|
|
.should.equal true
|
|
.should.equal true
|
|
|
|
|
|
|
|
-
|
|
|
|
|
it "should flush the project to the database", ->
|
|
it "should flush the project to the database", ->
|
|
|
@DocumentUpdaterHandler.flushProjectToMongo
|
|
@DocumentUpdaterHandler.flushProjectToMongo
|
|
|
.calledWith(@project_id)
|
|
.calledWith(@project_id)
|
|
@@ -203,29 +199,30 @@ describe "CompileManager", ->
|
|
|
describe "_checkIfAutoCompileLimitHasBeenHit", ->
|
|
describe "_checkIfAutoCompileLimitHasBeenHit", ->
|
|
|
|
|
|
|
|
it "should be able to compile if it is not an autocompile", (done)->
|
|
it "should be able to compile if it is not an autocompile", (done)->
|
|
|
- limit = {remaining:-1}
|
|
|
|
|
- @rateLimitGetStub.callsArgWith(0, null, limit)
|
|
|
|
|
|
|
+ @ratelimiter.addCount.callsArgWith(1, null, true)
|
|
|
@CompileManager._checkIfAutoCompileLimitHasBeenHit false, (err, canCompile)=>
|
|
@CompileManager._checkIfAutoCompileLimitHasBeenHit false, (err, canCompile)=>
|
|
|
canCompile.should.equal true
|
|
canCompile.should.equal true
|
|
|
done()
|
|
done()
|
|
|
|
|
|
|
|
it "should be able to compile if rate limit has remianing", (done)->
|
|
it "should be able to compile if rate limit has remianing", (done)->
|
|
|
- limit = {remaining:3}
|
|
|
|
|
- @rateLimitGetStub.callsArgWith(0, null, limit)
|
|
|
|
|
|
|
+ @ratelimiter.addCount.callsArgWith(1, null, true)
|
|
|
@CompileManager._checkIfAutoCompileLimitHasBeenHit true, (err, canCompile)=>
|
|
@CompileManager._checkIfAutoCompileLimitHasBeenHit true, (err, canCompile)=>
|
|
|
|
|
+ args = @ratelimiter.addCount.args[0][0]
|
|
|
|
|
+ args.throttle.should.equal 5
|
|
|
|
|
+ args.subjectName.should.equal "everyone"
|
|
|
|
|
+ args.timeInterval.should.equal 10
|
|
|
|
|
+ args.endpointName.should.equal "auto_compile"
|
|
|
canCompile.should.equal true
|
|
canCompile.should.equal true
|
|
|
done()
|
|
done()
|
|
|
|
|
|
|
|
it "should be not able to compile if rate limit has no remianing", (done)->
|
|
it "should be not able to compile if rate limit has no remianing", (done)->
|
|
|
- limit = {remaining:0}
|
|
|
|
|
- @rateLimitGetStub.callsArgWith(0, null, limit)
|
|
|
|
|
|
|
+ @ratelimiter.addCount.callsArgWith(1, null, false)
|
|
|
@CompileManager._checkIfAutoCompileLimitHasBeenHit true, (err, canCompile)=>
|
|
@CompileManager._checkIfAutoCompileLimitHasBeenHit true, (err, canCompile)=>
|
|
|
canCompile.should.equal false
|
|
canCompile.should.equal false
|
|
|
done()
|
|
done()
|
|
|
|
|
|
|
|
it "should return false if there is an error in the rate limit", (done)->
|
|
it "should return false if there is an error in the rate limit", (done)->
|
|
|
- limit = {remaining:4}
|
|
|
|
|
- @rateLimitGetStub.callsArgWith(0, "Err", limit)
|
|
|
|
|
|
|
+ @ratelimiter.addCount.callsArgWith(1, "error")
|
|
|
@CompileManager._checkIfAutoCompileLimitHasBeenHit true, (err, canCompile)=>
|
|
@CompileManager._checkIfAutoCompileLimitHasBeenHit true, (err, canCompile)=>
|
|
|
canCompile.should.equal false
|
|
canCompile.should.equal false
|
|
|
done()
|
|
done()
|