For duplicate ops only send ack to submitting client

When a duplicate op is received, we only need to ack it to client
that sent it. Only that client is having trouble, and all other clients
will already have received it.
This commit is contained in:
James Allen 2015-11-19 10:58:28 +00:00
parent 669cb0c085
commit 503b766dcc
2 changed files with 35 additions and 16 deletions

View file

@ -24,7 +24,7 @@ module.exports = DocumentUpdaterController =
if client.id == update.meta.source if client.id == update.meta.source
logger.log doc_id: doc_id, version: update.v, source: update.meta?.source, "distributing update to sender" logger.log doc_id: doc_id, version: update.v, source: update.meta?.source, "distributing update to sender"
client.emit "otUpdateApplied", v: update.v, doc: update.doc client.emit "otUpdateApplied", v: update.v, doc: update.doc
else else if !update.dup # Duplicate ops should just be sent back to sending client for acknowledgement
logger.log doc_id: doc_id, version: update.v, source: update.meta?.source, client_id: client.id, "distributing update to collaborator" logger.log doc_id: doc_id, version: update.v, source: update.meta?.source, client_id: client.id, "distributing update to collaborator"
client.emit "otUpdateApplied", update client.emit "otUpdateApplied", update

View file

@ -68,24 +68,43 @@ describe "DocumentUpdaterController", ->
doc: @doc_id doc: @doc_id
@io.sockets = @io.sockets =
clients: sinon.stub().returns([@sourceClient, @otherClients...]) clients: sinon.stub().returns([@sourceClient, @otherClients...])
@EditorUpdatesController._applyUpdateFromDocumentUpdater @io, @doc_id, @update
describe "normally", ->
beforeEach ->
@EditorUpdatesController._applyUpdateFromDocumentUpdater @io, @doc_id, @update
it "should send a version bump to the source client", -> it "should send a version bump to the source client", ->
@sourceClient.emit @sourceClient.emit
.calledWith("otUpdateApplied", v: @version, doc: @doc_id) .calledWith("otUpdateApplied", v: @version, doc: @doc_id)
.should.equal true
it "should get the clients connected to the document", ->
@io.sockets.clients
.calledWith(@doc_id)
.should.equal true
it "should send the full update to the other clients", ->
for client in @otherClients
client.emit
.calledWith("otUpdateApplied", @update)
.should.equal true .should.equal true
it "should get the clients connected to the document", ->
@io.sockets.clients
.calledWith(@doc_id)
.should.equal true
it "should send the full update to the other clients", ->
for client in @otherClients
client.emit
.calledWith("otUpdateApplied", @update)
.should.equal true
describe "with a duplicate op", ->
beforeEach ->
@update.dup = true
@EditorUpdatesController._applyUpdateFromDocumentUpdater @io, @doc_id, @update
it "should send a version bump to the source client as usual", ->
@sourceClient.emit
.calledWith("otUpdateApplied", v: @version, doc: @doc_id)
.should.equal true
it "should not send anything to the other clients (they've already had the op)", ->
for client in @otherClients
client.emit
.calledWith("otUpdateApplied")
.should.equal false
describe "_processErrorFromDocumentUpdater", -> describe "_processErrorFromDocumentUpdater", ->
beforeEach -> beforeEach ->
@clients = [new MockClient(), new MockClient()] @clients = [new MockClient(), new MockClient()]