add refreshExpiryTimeout function

on clsi all data lives inside of / dir
dynamically reduce size of EXPIRY_TIMEOUT if disk starts to get full
This commit is contained in:
Henry Oswald
2020-05-11 10:29:16 +01:00
parent 7254a025ae
commit c004d299c1
5 changed files with 102 additions and 5 deletions

View File

@@ -14,6 +14,7 @@
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
require('chai').should()
const assert = require('chai').assert
const modulePath = require('path').join(
__dirname,
'../../../app/js/ProjectPersistenceManager'
@@ -26,7 +27,15 @@ describe('ProjectPersistenceManager', function() {
requires: {
'./UrlCache': (this.UrlCache = {}),
'./CompileManager': (this.CompileManager = {}),
'logger-sharelatex': (this.logger = { log: sinon.stub() }),
diskusage: (this.diskusage = { check: sinon.stub() }),
'logger-sharelatex': (this.logger = {
log: sinon.stub(),
warn: sinon.stub(),
err: sinon.stub()
}),
'settings-sharelatex': (this.settings = {
project_cache_length_ms: 1000
}),
'./db': (this.db = {})
}
})
@@ -35,6 +44,57 @@ describe('ProjectPersistenceManager', function() {
return (this.user_id = '1234')
})
describe('refreshExpiryTimeout', function() {
it('should leave expiry alone if plenty of disk', function(done) {
this.diskusage.check.callsArgWith(1, null, {
available: 40,
total: 100
})
this.ProjectPersistenceManager.refreshExpiryTimeout(() => {
this.ProjectPersistenceManager.EXPIRY_TIMEOUT.should.equal(
this.settings.project_cache_length_ms
)
done()
})
})
it('should drop EXPIRY_TIMEOUT 10% if low disk usage', function(done) {
this.diskusage.check.callsArgWith(1, null, {
available: 5,
total: 100
})
this.ProjectPersistenceManager.refreshExpiryTimeout(() => {
this.ProjectPersistenceManager.EXPIRY_TIMEOUT.should.equal(900)
done()
})
})
it('should not drop EXPIRY_TIMEOUT to below 50% of project_cache_length_ms', function(done) {
this.diskusage.check.callsArgWith(1, null, {
available: 5,
total: 100
})
this.ProjectPersistenceManager.EXPIRY_TIMEOUT = 500
this.ProjectPersistenceManager.refreshExpiryTimeout(() => {
this.ProjectPersistenceManager.EXPIRY_TIMEOUT.should.equal(500)
done()
})
})
it('should not modify EXPIRY_TIMEOUT if there is an error getting disk values', function(done) {
this.diskusage.check.callsArgWith(1, 'Error', {
available: 5,
total: 100
})
this.ProjectPersistenceManager.refreshExpiryTimeout(() => {
this.ProjectPersistenceManager.EXPIRY_TIMEOUT.should.equal(1000)
done()
})
})
})
describe('clearExpiredProjects', function() {
beforeEach(function() {
this.project_ids = ['project-id-1', 'project-id-2']