diff --git a/services/chat/app.coffee b/services/chat/app.coffee index 8f5cc18dc0..3fad2e610e 100644 --- a/services/chat/app.coffee +++ b/services/chat/app.coffee @@ -3,9 +3,11 @@ settings = require 'settings-sharelatex' Server = require "./app/js/server" -port = settings.internal?.chat?.port or 3010 -host = settings.internal?.chat?.host or "localhost" +if !module.parent # Called directly + port = settings.internal?.chat?.port or 3010 + host = settings.internal?.chat?.host or "localhost" + Server.server.listen port, host, (error) -> + throw error if error? + logger.info "Chat starting up, listening on #{host}:#{port}" -Server.server.listen port, host, (error) -> - throw error if error? - logger.info "Chat starting up, listening on #{host}:#{port}" +module.exports = Server.server diff --git a/services/chat/test/acceptance/coffee/DeletingAMessageTests.coffee b/services/chat/test/acceptance/coffee/DeletingAMessageTests.coffee index 65c183d0f0..7d6ca8b00b 100644 --- a/services/chat/test/acceptance/coffee/DeletingAMessageTests.coffee +++ b/services/chat/test/acceptance/coffee/DeletingAMessageTests.coffee @@ -2,12 +2,14 @@ expect = require("chai").expect ChatClient = require "./helpers/ChatClient" +ChatApp = require "./helpers/ChatApp" describe "Deleting a message", -> - before -> + before (done) -> @project_id = ObjectId().toString() @user_id = ObjectId().toString() @thread_id = ObjectId().toString() + ChatApp.ensureRunning done describe "in a thread", -> before (done) -> diff --git a/services/chat/test/acceptance/coffee/DeletingAThreadTests.coffee b/services/chat/test/acceptance/coffee/DeletingAThreadTests.coffee index 850bcf0ef0..a803e730c7 100644 --- a/services/chat/test/acceptance/coffee/DeletingAThreadTests.coffee +++ b/services/chat/test/acceptance/coffee/DeletingAThreadTests.coffee @@ -3,11 +3,13 @@ expect = require("chai").expect crypto = require "crypto" ChatClient = require "./helpers/ChatClient" +ChatApp = require "./helpers/ChatApp" describe "Deleting a thread", -> - before -> + before (done) -> @project_id = ObjectId().toString() @user_id = ObjectId().toString() + ChatApp.ensureRunning done describe "with a thread that is deleted", -> before (done) -> diff --git a/services/chat/test/acceptance/coffee/EditingAMessageTests.coffee b/services/chat/test/acceptance/coffee/EditingAMessageTests.coffee index 51e14cfedd..f507e4b205 100644 --- a/services/chat/test/acceptance/coffee/EditingAMessageTests.coffee +++ b/services/chat/test/acceptance/coffee/EditingAMessageTests.coffee @@ -2,12 +2,14 @@ expect = require("chai").expect ChatClient = require "./helpers/ChatClient" +ChatApp = require "./helpers/ChatApp" describe "Editing a message", -> - before -> + before (done) -> @project_id = ObjectId().toString() @user_id = ObjectId().toString() @thread_id = ObjectId().toString() + ChatApp.ensureRunning done describe "in a thread", -> before (done) -> diff --git a/services/chat/test/acceptance/coffee/GettingMessagesTests.coffee b/services/chat/test/acceptance/coffee/GettingMessagesTests.coffee index 6d622b409a..b0c872e5cd 100644 --- a/services/chat/test/acceptance/coffee/GettingMessagesTests.coffee +++ b/services/chat/test/acceptance/coffee/GettingMessagesTests.coffee @@ -4,13 +4,15 @@ async = require "async" crypto = require "crypto" ChatClient = require "./helpers/ChatClient" +ChatApp = require "./helpers/ChatApp" describe "Getting messages", -> - before -> + before (done) -> @user_id1 = ObjectId().toString() @user_id2 = ObjectId().toString() @content1 = "foo bar" @content2 = "hello world" + ChatApp.ensureRunning done describe "globally", -> before (done) -> diff --git a/services/chat/test/acceptance/coffee/ResolvingAThreadTests.coffee b/services/chat/test/acceptance/coffee/ResolvingAThreadTests.coffee index 4f666666ac..d162f881f6 100644 --- a/services/chat/test/acceptance/coffee/ResolvingAThreadTests.coffee +++ b/services/chat/test/acceptance/coffee/ResolvingAThreadTests.coffee @@ -3,11 +3,14 @@ expect = require("chai").expect crypto = require "crypto" ChatClient = require "./helpers/ChatClient" +ChatApp = require "./helpers/ChatApp" describe "Resolving a thread", -> - before -> + before (done) -> @project_id = ObjectId().toString() @user_id = ObjectId().toString() + ChatApp.ensureRunning done + describe "with a resolved thread", -> before (done) -> @thread_id = ObjectId().toString() diff --git a/services/chat/test/acceptance/coffee/SendingAMessageTests.coffee b/services/chat/test/acceptance/coffee/SendingAMessageTests.coffee index 77af23bda7..64a2d5dbe5 100644 --- a/services/chat/test/acceptance/coffee/SendingAMessageTests.coffee +++ b/services/chat/test/acceptance/coffee/SendingAMessageTests.coffee @@ -2,9 +2,11 @@ expect = require("chai").expect ChatClient = require "./helpers/ChatClient" +ChatApp = require "./helpers/ChatApp" describe "Sending a message", -> - before -> + before (done) -> + ChatApp.ensureRunning done describe "globally", -> before (done) -> diff --git a/services/chat/test/acceptance/coffee/helpers/ChatApp.coffee b/services/chat/test/acceptance/coffee/helpers/ChatApp.coffee new file mode 100644 index 0000000000..8973541003 --- /dev/null +++ b/services/chat/test/acceptance/coffee/helpers/ChatApp.coffee @@ -0,0 +1,20 @@ +app = require('../../../../app') +require("logger-sharelatex").logger.level("error") + +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 3010, "localhost", (error) => + throw error if error? + @running = true + for callback in @callbacks + callback() \ No newline at end of file