diff --git a/services/filestore/Jenkinsfile b/services/filestore/Jenkinsfile index ffc7265888..e1a34a5235 100644 --- a/services/filestore/Jenkinsfile +++ b/services/filestore/Jenkinsfile @@ -21,7 +21,11 @@ pipeline { } } - + stage('Acceptance Tests') { + steps { + sh 'DOCKER_COMPOSE_FLAGS="-f docker-compose.ci.yml" make test_acceptance' + } + } stage('Package and publish build') { steps { diff --git a/services/filestore/app.coffee b/services/filestore/app.coffee index bd693af655..a6d6d11119 100644 --- a/services/filestore/app.coffee +++ b/services/filestore/app.coffee @@ -110,9 +110,8 @@ app.get "/health_check", healthCheckController.check app.get '*', (req, res)-> res.send 404 -server = require('http').createServer(app) -port = settings.internal.filestore.port or 3009 -host = "0.0.0.0" + + beginShutdown = () -> if appIsOk @@ -122,14 +121,22 @@ beginShutdown = () -> process.exit 1 , 120*1000 killTimer.unref?() # prevent timer from keeping process alive - server.close () -> + app.close () -> logger.log "closed all connections" Metrics.close() process.disconnect?() logger.log "server will stop accepting connections" -server.listen port, -> - logger.info "Filestore starting up, listening on #{host}:#{port}" + +port = settings.internal.filestore.port or 3009 +host = "0.0.0.0" + +if !module.parent # Called directly + app.listen port, host, (error) -> + logger.info "Filestore starting up, listening on #{host}:#{port}" + + +module.exports = app process.on 'SIGTERM', () -> logger.log("filestore got SIGTERM, shutting down gracefully") diff --git a/services/filestore/app/coffee/FileConverter.coffee b/services/filestore/app/coffee/FileConverter.coffee index 429fa7fccb..894b0e89fd 100644 --- a/services/filestore/app/coffee/FileConverter.coffee +++ b/services/filestore/app/coffee/FileConverter.coffee @@ -34,11 +34,11 @@ module.exports = callback(err, destPath) thumbnail: (sourcePath, callback)-> - logger.log sourcePath:sourcePath, "thumbnail convert file" destPath = "#{sourcePath}.png" sourcePath = "#{sourcePath}[0]" width = "260x" command = ["convert", "-flatten", "-background", "white", "-density", "300", "-define", "pdf:fit-page=#{width}", sourcePath, "-resize", width, destPath] + logger.log sourcePath:sourcePath, destPath:destPath, command:command, "thumbnail convert file" command = Settings.commands.convertCommandPrefix.concat(command) safe_exec command, childProcessOpts, (err, stdout, stderr)-> if err? diff --git a/services/filestore/package.json b/services/filestore/package.json index 9694fc6679..198a6ec366 100644 --- a/services/filestore/package.json +++ b/services/filestore/package.json @@ -24,7 +24,7 @@ "async": "~0.2.10", "aws-sdk": "^2.1.39", "coffee-script": "~1.7.1", - "express": "~3.4.8", + "express": "^4.2.0", "fs-extra": "^1.0.0", "heapdump": "^0.3.2", "knox": "~0.9.1", diff --git a/services/filestore/test/acceptance/coffee/FilestoreApp.coffee b/services/filestore/test/acceptance/coffee/FilestoreApp.coffee new file mode 100644 index 0000000000..818e90ec6f --- /dev/null +++ b/services/filestore/test/acceptance/coffee/FilestoreApp.coffee @@ -0,0 +1,24 @@ +app = require('../../../app') +require("logger-sharelatex").logger.level("info") +logger = require("logger-sharelatex") +Settings = require("settings-sharelatex") + +module.exports = + running: false + initing: false + callbacks: [] + ensureRunning: (callback = (error) ->) -> + if @running + return callback() + else if @initing + @callbacks.push callback + else + @initing = true + @callbacks.push callback + app.listen Settings.internal?.filestore?.port, "localhost", (error) => + throw error if error? + @running = true + logger.log("filestore running in dev mode") + + for callback in @callbacks + callback() \ No newline at end of file diff --git a/services/filestore/test/acceptance/coffee/SendingFileTest.coffee b/services/filestore/test/acceptance/coffee/SendingFileTest.coffee index 2731e25565..1b20e6b44f 100644 --- a/services/filestore/test/acceptance/coffee/SendingFileTest.coffee +++ b/services/filestore/test/acceptance/coffee/SendingFileTest.coffee @@ -1,4 +1,3 @@ - assert = require("chai").assert sinon = require('sinon') chai = require('chai') @@ -9,6 +8,7 @@ SandboxedModule = require('sandboxed-module') fs = require("fs") request = require("request") settings = require("settings-sharelatex") +FilestoreApp = require "./FilestoreApp" describe "Filestore", -> @@ -26,8 +26,9 @@ describe "Filestore", -> @filestoreUrl = "http://localhost:#{settings.internal.filestore.port}" beforeEach (done)-> - fs.unlink @localFileWritePath, => - done() + FilestoreApp.ensureRunning => + fs.unlink @localFileWritePath, -> + done()