diff --git a/services/filestore/Gruntfile.coffee b/services/filestore/Gruntfile.coffee index 6534dedc09..aa40cf7460 100644 --- a/services/filestore/Gruntfile.coffee +++ b/services/filestore/Gruntfile.coffee @@ -19,6 +19,14 @@ module.exports = (grunt) -> ext: '.js' server_tests: + expand: true, + flatten: false, + cwd: 'test/acceptence/coffee', + src: ['*.coffee', '**/*.coffee'], + dest: 'test/acceptence/js/', + ext: '.js' + + server_acc_tests: expand: true, flatten: false, cwd: 'test/unit/coffee', @@ -35,8 +43,10 @@ module.exports = (grunt) -> nodemon: dev: + script: 'app.js' options: - file: 'app.js' + ext:"*.coffee" + concurrent: dev: @@ -50,7 +60,12 @@ module.exports = (grunt) -> options: reporter: grunt.option('reporter') or 'spec' grep: grunt.option("grep") - + acceptence: + src: ["test/acceptence/js/#{grunt.option('feature') or '**'}/*.js"] + options: + reporter: grunt.option('reporter') or 'spec' + grep: grunt.option("grep") + grunt.loadNpmTasks 'grunt-contrib-coffee' grunt.loadNpmTasks 'grunt-contrib-watch' @@ -60,6 +75,8 @@ module.exports = (grunt) -> grunt.loadNpmTasks 'grunt-mocha-test' grunt.registerTask "test:unit", ["coffee", "mochaTest:unit"] + grunt.registerTask "test:acceptence", ["coffee", "mochaTest:acceptence"] + grunt.registerTask "ci", "test:unit" grunt.registerTask 'default', ['coffee', 'concurrent'] diff --git a/services/filestore/app/coffee/LocalFileWriter.coffee b/services/filestore/app/coffee/LocalFileWriter.coffee index a839c46656..12d505b05b 100644 --- a/services/filestore/app/coffee/LocalFileWriter.coffee +++ b/services/filestore/app/coffee/LocalFileWriter.coffee @@ -34,4 +34,5 @@ module.exports = if !key? key = uuid.v1() key = key.replace(/\//g,"-") + console.log Settings.path.uploadFolder, key path.join(Settings.path.uploadFolder, key) diff --git a/services/filestore/app/coffee/S3PersistorManager.coffee b/services/filestore/app/coffee/S3PersistorManager.coffee index 703241920d..a6e8d18243 100644 --- a/services/filestore/app/coffee/S3PersistorManager.coffee +++ b/services/filestore/app/coffee/S3PersistorManager.coffee @@ -13,14 +13,6 @@ _ = require("underscore") thirtySeconds = 30 * 1000 - -printSockets = -> - console.log require('https').globalAgent.sockets - console.log require('http').globalAgent.sockets - setTimeout printSockets, thirtySeconds - -printSockets() - buildDefaultOptions = (bucketName, method, key)-> return { aws: @@ -56,7 +48,6 @@ module.exports = logger.err err:err, bucketName:bucketName, key:key, fsPath:fsPath, "error emmited on put of file" callback err - sendStream: (bucketName, key, readStream, callback)-> logger.log bucketName:bucketName, key:key, "sending file to s3" readStream.on "error", (err)-> diff --git a/services/filestore/package.json b/services/filestore/package.json index 15a5fa18ab..5b97e24e40 100644 --- a/services/filestore/package.json +++ b/services/filestore/package.json @@ -27,7 +27,7 @@ "grunt-contrib-requirejs": "0.4.1", "grunt-contrib-coffee": "0.7.0", "grunt-contrib-watch": "0.5.3", - "grunt-nodemon": "0.1.2", + "grunt-nodemon": "0.2.1", "grunt-contrib-clean": "0.5.0", "grunt-concurrent": "0.4.2" } diff --git a/services/filestore/test/acceptence/coffee/SendingFileTest.coffee b/services/filestore/test/acceptence/coffee/SendingFileTest.coffee new file mode 100644 index 0000000000..db7625afb8 --- /dev/null +++ b/services/filestore/test/acceptence/coffee/SendingFileTest.coffee @@ -0,0 +1,55 @@ + +assert = require("chai").assert +sinon = require('sinon') +chai = require('chai') +should = chai.should() +expect = chai.expect +modulePath = "../../../app/js/LocalFileWriter.js" +SandboxedModule = require('sandboxed-module') +fs = require("fs") +request = require("request") +settings = require("settings-sharelatex") + +describe "Sending a file", -> + + before (done)-> + @localFileReadPath = "/tmp/filestore_acceptence_tests_file_read.txt" + @localFileWritePath = "/tmp/filestore_acceptence_tests_file_write.txt" + + @constantFileContent = [ + "hello world" + "line 2 goes here #{Math.random()}" + "there are 3 lines in all" + ].join("\n") + + fs.writeFile(@localFileReadPath, @constantFileContent, done) + @filestoreUrl = "http://localhost:#{settings.internal.filestore.port}" + + beforeEach (done)-> + fs.unlink @localFileWritePath, -> + done() + + + + it "should send a 200 for status endpoing", (done)-> + request "#{@filestoreUrl}/status", (err, response, body)-> + response.statusCode.should.equal 200 + body.indexOf("filestore").should.not.equal -1 + body.indexOf("up").should.not.equal -1 + done() + + it "should be able get the file back", (done)-> + @timeout(1000 * 10) + @fileUrl = "#{@filestoreUrl}/project/acceptence_tests/file/12345" + + writeStream = request.post(@fileUrl) + + writeStream.on "end", => + request.get @fileUrl, (err, response, body)=> + body.should.equal @constantFileContent + done() + + fs.createReadStream(@localFileReadPath).pipe writeStream + + +