[WebsocketController] handle redis subscribe error on joinProject

joinProject should not complete when the redis pub/sub subscribe request
 failed.
This commit is contained in:
Jakob Ackermann 2020-05-12 12:45:46 +02:00
parent f4b17ebbad
commit 684cb3903c
2 changed files with 23 additions and 0 deletions

View file

@ -40,6 +40,7 @@ module.exports = WebsocketController =
client.set("is_restricted_user", !!(isRestrictedUser))
RoomManager.joinProject client, project_id, (err) ->
return callback(err) if err
logger.log {user_id, project_id, client_id: client.id}, "user joined project"
callback null, project, privilegeLevel, WebsocketController.PROTOCOL_VERSION

View file

@ -125,6 +125,28 @@ describe 'WebsocketController', ->
it "should not log an error", ->
@logger.error.called.should.equal false
describe "when the subscribe failed", ->
beforeEach ->
@client.id = "mock-client-id"
@project = {
name: "Test Project"
owner: {
_id: @owner_id = "mock-owner-id-123"
}
}
@privilegeLevel = "owner"
@ConnectedUsersManager.updateUserPosition = sinon.stub().callsArg(4)
@isRestrictedUser = true
@WebApiManager.joinProject = sinon.stub().callsArgWith(2, null, @project, @privilegeLevel, @isRestrictedUser)
@RoomManager.joinProject = sinon.stub().callsArgWith(2, new Error("subscribe failed"))
@WebsocketController.joinProject @client, @user, @project_id, @callback
it "should return an error", ->
@callback
.calledWith(new Error("subscribe failed"))
.should.equal true
@callback.args[0][0].message.should.equal "subscribe failed"
describe "leaveProject", ->
beforeEach ->
@DocumentUpdaterManager.flushProjectToMongoAndDelete = sinon.stub().callsArg(1)