mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
Log out and put the last update back when an error occurs
This commit is contained in:
@@ -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) ->
|
||||
|
||||
@@ -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 ->
|
||||
|
||||
Reference in New Issue
Block a user