1
0
Fork 0
mirror of https://github.com/overleaf/overleaf.git synced 2025-04-08 10:13:21 +00:00

added container monitor cleanup to fix hanging tests

This commit is contained in:
mserranom 2020-02-20 17:24:28 +01:00
parent 4c0fd2b6f4
commit fa37ed865a
5 changed files with 27 additions and 17 deletions

View file

@ -35,6 +35,9 @@ const usingSiblingContainers = () =>
x => x.sandboxedCompilesHostDir
) != null
let containerMonitorTimeout
let containerMonitorInterval
module.exports = DockerRunner = {
ERR_NOT_DIRECTORY: new Error('not a directory'),
ERR_TERMINATED: new Error('terminated'),
@ -646,17 +649,29 @@ module.exports = DockerRunner = {
{ maxAge: DockerRunner.MAX_CONTAINER_AGE },
'starting container expiry'
)
// guarantee only one monitor is running
DockerRunner.stopContainerMonitor()
// randomise the start time
const randomDelay = Math.floor(Math.random() * 5 * 60 * 1000)
return setTimeout(
() =>
setInterval(
() => DockerRunner.destroyOldContainers(),
(oneHour = 60 * 60 * 1000)
),
containerMonitorTimeout = setTimeout(() => {
containerMonitorInterval = setInterval(
() => DockerRunner.destroyOldContainers(),
(oneHour = 60 * 60 * 1000)
)
}, randomDelay)
},
randomDelay
)
stopContainerMonitor() {
if (containerMonitorTimeout) {
clearTimeout(containerMonitorTimeout)
containerMonitorTimeout = undefined
}
if (containerMonitorInterval) {
clearInterval(containerMonitorTimeout)
containerMonitorTimeout = undefined
}
}
}

View file

@ -1536,12 +1536,6 @@
"resolved": "https://registry.npmjs.org/coffee-script/-/coffee-script-1.6.0.tgz",
"integrity": "sha1-gIs5bhEPU9AhoZpO8fZb4OjjX6M="
},
"coffeescript": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/coffeescript/-/coffeescript-1.6.0.tgz",
"integrity": "sha1-bdTeHrYveE2MjYCWdVLLpUf/2d4=",
"dev": true
},
"color-convert": {
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",

View file

@ -44,7 +44,6 @@
"babel-eslint": "^10.0.3",
"bunyan": "^0.22.1",
"chai": "~1.8.1",
"coffeescript": "1.6.0",
"eslint": "^6.6.0",
"eslint-config-prettier": "^6.10.0",
"eslint-config-standard": "^14.1.0",

View file

@ -12,7 +12,6 @@
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
require('chai').should()
require('coffee-script')
const modulePath = require('path').join(
__dirname,
'../../../app/js/DockerLockManager'

View file

@ -17,7 +17,6 @@ const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
require('chai').should()
const { expect } = require('chai')
require('coffee-script')
const modulePath = require('path').join(
__dirname,
'../../../app/js/DockerRunner'
@ -89,6 +88,10 @@ describe('DockerRunner', function() {
return (this.Settings.clsi.docker.env = { PATH: 'mock-path' })
})
afterEach(function() {
this.DockerRunner.stopContainerMonitor()
})
describe('run', function() {
beforeEach(function(done) {
this.DockerRunner._getContainerOptions = sinon