From 56fda1f9b00f31e98a64fe5f37e81fc35ceac765 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Fri, 21 Feb 2020 13:59:23 +0000 Subject: [PATCH 1/3] [misc] test/acceptance: use the correct redis instances --- .../real-time/test/acceptance/coffee/ApplyUpdateTests.coffee | 2 +- .../real-time/test/acceptance/coffee/ReceiveUpdateTests.coffee | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/real-time/test/acceptance/coffee/ApplyUpdateTests.coffee b/services/real-time/test/acceptance/coffee/ApplyUpdateTests.coffee index e7babeb81c..f2437f2641 100644 --- a/services/real-time/test/acceptance/coffee/ApplyUpdateTests.coffee +++ b/services/real-time/test/acceptance/coffee/ApplyUpdateTests.coffee @@ -8,7 +8,7 @@ FixturesManager = require "./helpers/FixturesManager" settings = require "settings-sharelatex" redis = require "redis-sharelatex" -rclient = redis.createClient(settings.redis.websessions) +rclient = redis.createClient(settings.redis.documentupdater) redisSettings = settings.redis diff --git a/services/real-time/test/acceptance/coffee/ReceiveUpdateTests.coffee b/services/real-time/test/acceptance/coffee/ReceiveUpdateTests.coffee index fb504dd9aa..7f04fd8adb 100644 --- a/services/real-time/test/acceptance/coffee/ReceiveUpdateTests.coffee +++ b/services/real-time/test/acceptance/coffee/ReceiveUpdateTests.coffee @@ -10,7 +10,7 @@ async = require "async" settings = require "settings-sharelatex" redis = require "redis-sharelatex" -rclient = redis.createClient(settings.redis.websessions) +rclient = redis.createClient(settings.redis.pubsub) describe "receiveUpdate", -> before (done) -> From 83e3ff0ed7dc04874b7fbdd5463877bf05d17da6 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Fri, 21 Feb 2020 14:13:30 +0000 Subject: [PATCH 2/3] [misc] test/acceptance: ReceiveUpdateTests: add 2nd project/3rd client ...and check for cross project leakage. --- .../coffee/ReceiveUpdateTests.coffee | 125 +++++++++++++++--- 1 file changed, 105 insertions(+), 20 deletions(-) diff --git a/services/real-time/test/acceptance/coffee/ReceiveUpdateTests.coffee b/services/real-time/test/acceptance/coffee/ReceiveUpdateTests.coffee index 7f04fd8adb..4da68b76c5 100644 --- a/services/real-time/test/acceptance/coffee/ReceiveUpdateTests.coffee +++ b/services/real-time/test/acceptance/coffee/ReceiveUpdateTests.coffee @@ -13,7 +13,7 @@ redis = require "redis-sharelatex" rclient = redis.createClient(settings.redis.pubsub) describe "receiveUpdate", -> - before (done) -> + beforeEach (done) -> @lines = ["test", "doc", "lines"] @version = 42 @ops = ["mock", "doc", "ops"] @@ -52,15 +52,52 @@ describe "receiveUpdate", -> (cb) => @clientB.emit "joinDoc", @doc_id, cb + + (cb) => + FixturesManager.setUpProject { + privilegeLevel: "owner" + project: {name: "Test Project"} + }, (error, {user_id: @user_id_second, project_id: @project_id_second}) => cb() + + (cb) => + FixturesManager.setUpDoc @project_id_second, {@lines, @version, @ops}, (e, {doc_id: @doc_id_second}) => + cb(e) + + (cb) => + @clientC = RealTimeClient.connect() + @clientC.on "connectionAccepted", cb + + (cb) => + @clientC.emit "joinProject", { + project_id: @project_id_second + }, cb + (cb) => + @clientC.emit "joinDoc", @doc_id_second, cb + + (cb) => + @clientAUpdates = [] + @clientA.on "otUpdateApplied", (update) => @clientAUpdates.push(update) + @clientBUpdates = [] + @clientB.on "otUpdateApplied", (update) => @clientBUpdates.push(update) + @clientCUpdates = [] + @clientC.on "otUpdateApplied", (update) => @clientCUpdates.push(update) + + @clientAErrors = [] + @clientA.on "otUpdateError", (error) => @clientAErrors.push(error) + @clientBErrors = [] + @clientB.on "otUpdateError", (error) => @clientBErrors.push(error) + @clientCErrors = [] + @clientC.on "otUpdateError", (error) => @clientCErrors.push(error) + cb() ], done - + + afterEach () -> + @clientA?.disconnect() + @clientB?.disconnect() + @clientC?.disconnect() + describe "with an update from clientA", -> - before (done) -> - @clientAUpdates = [] - @clientA.on "otUpdateApplied", (update) => @clientAUpdates.push(update) - @clientBUpdates = [] - @clientB.on "otUpdateApplied", (update) => @clientBUpdates.push(update) - + beforeEach (done) -> @update = { doc_id: @doc_id op: @@ -80,21 +117,69 @@ describe "receiveUpdate", -> @clientAUpdates.should.deep.equal [{ v: @version, doc: @doc_id }] - - describe "with an error", -> - before (done) -> - @clientAErrors = [] - @clientA.on "otUpdateError", (error) => @clientAErrors.push(error) - @clientBErrors = [] - @clientB.on "otUpdateError", (error) => @clientBErrors.push(error) - + + it "should send nothing to clientC", -> + @clientCUpdates.should.deep.equal [] + + describe "with an update from clientC", -> + beforeEach (done) -> + @update = { + doc_id: @doc_id_second + op: + meta: + source: @clientC.publicId + v: @version + doc: @doc_id_second + op: [{i: "update from clientC", p: 50}] + } + rclient.publish "applied-ops", JSON.stringify(@update) + setTimeout done, 200 # Give clients time to get message + + it "should send nothing to clientA", -> + @clientAUpdates.should.deep.equal [] + + it "should send nothing to clientB", -> + @clientBUpdates.should.deep.equal [] + + it "should send an ack to clientC", -> + @clientCUpdates.should.deep.equal [{ + v: @version, doc: @doc_id_second + }] + + describe "with an error for the first project", -> + beforeEach (done) -> rclient.publish "applied-ops", JSON.stringify({doc_id: @doc_id, error: @error = "something went wrong"}) setTimeout done, 200 # Give clients time to get message - - it "should send the error to both clients", -> + + it "should send the error to the clients in the first project", -> @clientAErrors.should.deep.equal [@error] @clientBErrors.should.deep.equal [@error] - - it "should disconnect the clients", -> + + it "should not send any errors to the client in the second project", -> + @clientCErrors.should.deep.equal [] + + it "should disconnect the clients of the first project", -> @clientA.socket.connected.should.equal false @clientB.socket.connected.should.equal false + + it "should not disconnect the client in the second project", -> + @clientC.socket.connected.should.equal true + + describe "with an error for the second project", -> + beforeEach (done) -> + rclient.publish "applied-ops", JSON.stringify({doc_id: @doc_id_second, error: @error = "something went wrong"}) + setTimeout done, 200 # Give clients time to get message + + it "should not send any errors to the clients in the first project", -> + @clientAErrors.should.deep.equal [] + @clientBErrors.should.deep.equal [] + + it "should send the error to the client in the second project", -> + @clientCErrors.should.deep.equal [@error] + + it "should not disconnect the clients of the first project", -> + @clientA.socket.connected.should.equal true + @clientB.socket.connected.should.equal true + + it "should disconnect the client in the second project", -> + @clientC.socket.connected.should.equal false From b2e4448992512edc7e10cd88e6bbf3796548c807 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Wed, 26 Feb 2020 17:56:57 +0100 Subject: [PATCH 3/3] [misc] test/acceptance: ReceiveUpdateTests: test remotely sent update --- .../coffee/ReceiveUpdateTests.coffee | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/services/real-time/test/acceptance/coffee/ReceiveUpdateTests.coffee b/services/real-time/test/acceptance/coffee/ReceiveUpdateTests.coffee index 4da68b76c5..da9ee0ca36 100644 --- a/services/real-time/test/acceptance/coffee/ReceiveUpdateTests.coffee +++ b/services/real-time/test/acceptance/coffee/ReceiveUpdateTests.coffee @@ -146,6 +146,29 @@ describe "receiveUpdate", -> v: @version, doc: @doc_id_second }] + describe "with an update from a remote client for project 1", -> + beforeEach (done) -> + @update = { + doc_id: @doc_id + op: + meta: + source: 'this-is-a-remote-client-id' + v: @version + doc: @doc_id + op: [{i: "foo", p: 50}] + } + rclient.publish "applied-ops", JSON.stringify(@update) + setTimeout done, 200 # Give clients time to get message + + it "should send the full op to clientA", -> + @clientAUpdates.should.deep.equal [@update.op] + + it "should send the full op to clientB", -> + @clientBUpdates.should.deep.equal [@update.op] + + it "should send nothing to clientC", -> + @clientCUpdates.should.deep.equal [] + describe "with an error for the first project", -> beforeEach (done) -> rclient.publish "applied-ops", JSON.stringify({doc_id: @doc_id, error: @error = "something went wrong"})