Log out and put the last update back when an error occurs

This commit is contained in:
James Allen 2014-03-05 13:22:38 +00:00
parent e4d8cc7a11
commit 188d620ce1
2 changed files with 14 additions and 2 deletions

View file

@ -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) ->

View file

@ -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 ->