mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #47 from sharelatex/bg-add-message-ids
include a unique id in every message published to redis
This commit is contained in:
commit
1052e9e000
3 changed files with 22 additions and 1 deletions
|
@ -2,6 +2,12 @@ Settings = require('settings-sharelatex')
|
|||
rclient = require("redis-sharelatex").createClient(Settings.redis.realtime)
|
||||
Keys = Settings.redis.realtime.key_schema
|
||||
logger = require('logger-sharelatex')
|
||||
os = require "os"
|
||||
crypto = require "crypto"
|
||||
|
||||
HOST = os.hostname()
|
||||
RND = crypto.randomBytes(4).toString('hex') # generate a random key for this process
|
||||
COUNT = 0
|
||||
|
||||
MAX_OPS_PER_ITERATION = 8 # process a limited number of ops for safety
|
||||
|
||||
|
@ -26,4 +32,7 @@ module.exports = RealTimeRedisManager =
|
|||
rclient.llen Keys.pendingUpdates({doc_id}), callback
|
||||
|
||||
sendData: (data) ->
|
||||
# create a unique message id using a counter
|
||||
message_id = "doc:#{HOST}:#{RND}-#{COUNT++}"
|
||||
data?._id = message_id
|
||||
rclient.publish "applied-ops", JSON.stringify(data)
|
||||
|
|
|
@ -232,7 +232,7 @@ describe "Applying updates to a doc", ->
|
|||
@messageCallback.called.should.equal true
|
||||
[channel, message] = @messageCallback.args[0]
|
||||
channel.should.equal "applied-ops"
|
||||
JSON.parse(message).should.deep.equal {
|
||||
JSON.parse(message).should.deep.include {
|
||||
project_id: @project_id,
|
||||
doc_id: @doc_id,
|
||||
error:'Delete component \'not the correct content\' does not match deleted text \'one\ntwo\nthree\''
|
||||
|
|
|
@ -19,6 +19,9 @@ describe "RealTimeRedisManager", ->
|
|||
key_schema:
|
||||
pendingUpdates: ({doc_id}) -> "PendingUpdates:#{doc_id}"
|
||||
"logger-sharelatex": { log: () -> }
|
||||
"crypto": @crypto = { randomBytes: sinon.stub().withArgs(4).returns(Buffer.from([0x1, 0x2, 0x3, 0x4])) }
|
||||
"os": @os = {hostname: sinon.stub().returns("somehost")}
|
||||
|
||||
@doc_id = "doc-id-123"
|
||||
@project_id = "project-id-123"
|
||||
@callback = sinon.stub()
|
||||
|
@ -74,3 +77,12 @@ describe "RealTimeRedisManager", ->
|
|||
|
||||
it "should return the length", ->
|
||||
@callback.calledWith(null, @length).should.equal true
|
||||
|
||||
describe "sendData", ->
|
||||
beforeEach ->
|
||||
@message_id = "doc:somehost:01020304-0"
|
||||
@rclient.publish = sinon.stub()
|
||||
@RealTimeRedisManager.sendData({op: "thisop"})
|
||||
|
||||
it "should send the op with a message id", ->
|
||||
@rclient.publish.calledWith("applied-ops", JSON.stringify({op:"thisop",_id:@message_id})).should.equal true
|
Loading…
Reference in a new issue