From 188d620ce1c4b48b08ebe9509f423091107690a1 Mon Sep 17 00:00:00 2001 From: James Allen Date: Wed, 5 Mar 2014 13:22:38 +0000 Subject: [PATCH] Log out and put the last update back when an error occurs --- services/track-changes/app/coffee/HistoryManager.coffee | 8 +++++++- .../unit/coffee/HistoryManager/HistoryManagerTests.coffee | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/services/track-changes/app/coffee/HistoryManager.coffee b/services/track-changes/app/coffee/HistoryManager.coffee index 41feff05c3..276d31ad1c 100644 --- a/services/track-changes/app/coffee/HistoryManager.coffee +++ b/services/track-changes/app/coffee/HistoryManager.coffee @@ -21,7 +21,13 @@ module.exports = HistoryManager = rawUpdates.shift() if rawUpdates[0]? and rawUpdates[0].v != lastCompressedUpdate.v + 1 - return callback new Error("Tried to apply raw op at version #{rawUpdates[0].v} to last compressed update with version #{lastCompressedUpdate.v}") + error = new Error("Tried to apply raw op at version #{rawUpdates[0].v} to last compressed update with version #{lastCompressedUpdate.v}") + logger.error err: error, doc_id: doc_id, "inconsistent doc versions" + # Push the update back into Mongo - catching errors at this + # point is useless, we're already bailing + MongoManager.insertCompressedUpdates doc_id, [lastCompressedUpdate], () -> + return callback error + return compressedUpdates = UpdateCompressor.compressRawUpdates lastCompressedUpdate, rawUpdates MongoManager.insertCompressedUpdates doc_id, compressedUpdates, (error) -> diff --git a/services/track-changes/test/unit/coffee/HistoryManager/HistoryManagerTests.coffee b/services/track-changes/test/unit/coffee/HistoryManager/HistoryManagerTests.coffee index 88efcfe606..e58c2fc44c 100644 --- a/services/track-changes/test/unit/coffee/HistoryManager/HistoryManagerTests.coffee +++ b/services/track-changes/test/unit/coffee/HistoryManager/HistoryManagerTests.coffee @@ -12,7 +12,7 @@ describe "HistoryManager", -> "./MongoManager" : @MongoManager = {} "./RedisManager" : @RedisManager = {} "./LockManager" : @LockManager = {} - "logger-sharelatex": { log: sinon.stub() } + "logger-sharelatex": { log: sinon.stub(), error: sinon.stub() } @doc_id = "doc-id-123" @callback = sinon.stub() @@ -111,6 +111,12 @@ describe "HistoryManager", -> .calledWith(new Error("Tried to apply raw op at version 13 to last compressed update with version 11")) .should.equal true + it "should put the popped update back into mongo", -> + @MongoManager.insertCompressedUpdates.calledOnce.should.equal true + @MongoManager.insertCompressedUpdates + .calledWith(@doc_id, [@lastCompressedUpdate]) + .should.equal true + describe "processUncompressedUpdates", -> describe "when there is fewer than one batch to send", -> beforeEach ->