mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-29 19:14:41 +00:00
Merge pull request #25 from sharelatex/bg-error-on-out-of-order-ops
return error when out-of-order ops detected
This commit is contained in:
commit
5989d8f27f
2 changed files with 21 additions and 0 deletions
|
@ -16,6 +16,13 @@ module.exports = UpdatesManager =
|
||||||
if length == 0
|
if length == 0
|
||||||
return callback()
|
return callback()
|
||||||
|
|
||||||
|
# check that ops are in the correct order
|
||||||
|
for op, i in rawUpdates when i > 0
|
||||||
|
thisVersion = op?.v
|
||||||
|
prevVersion = rawUpdates[i-1]?.v
|
||||||
|
if not (prevVersion < thisVersion)
|
||||||
|
logger.error project_id: project_id, doc_id: doc_id, rawUpdates:rawUpdates, temporary: temporary, thisVersion:thisVersion, prevVersion:prevVersion, "op versions out of order"
|
||||||
|
|
||||||
# FIXME: we no longer need the lastCompressedUpdate, so change functions not to need it
|
# FIXME: we no longer need the lastCompressedUpdate, so change functions not to need it
|
||||||
# CORRECTION: we do use it to log the time in case of error
|
# CORRECTION: we do use it to log the time in case of error
|
||||||
MongoManager.peekLastCompressedUpdate doc_id, (error, lastCompressedUpdate, lastVersion) ->
|
MongoManager.peekLastCompressedUpdate doc_id, (error, lastCompressedUpdate, lastVersion) ->
|
||||||
|
|
|
@ -137,6 +137,20 @@ describe "UpdatesManager", ->
|
||||||
it "should not insert any update into mongo", ->
|
it "should not insert any update into mongo", ->
|
||||||
@PackManager.insertCompressedUpdates.called.should.equal false
|
@PackManager.insertCompressedUpdates.called.should.equal false
|
||||||
|
|
||||||
|
describe "when the raw ops are out of order", ->
|
||||||
|
beforeEach ->
|
||||||
|
@rawUpdates = [{ v: 13, op: "mock-op-13" }, { v: 12, op: "mock-op-12" }]
|
||||||
|
@UpdatesManager.compressAndSaveRawUpdates @project_id, @doc_id, @rawUpdates, @temporary, @callback
|
||||||
|
|
||||||
|
it "should call the callback with an error", ->
|
||||||
|
@callback
|
||||||
|
.calledWith(new Error)
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
|
it "should not insert any update into mongo", ->
|
||||||
|
@PackManager.insertCompressedUpdates.called.should.equal false
|
||||||
|
|
||||||
|
|
||||||
describe "when the raw ops need appending to existing history which is in S3", ->
|
describe "when the raw ops need appending to existing history which is in S3", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@lastCompressedUpdate = null
|
@lastCompressedUpdate = null
|
||||||
|
|
Loading…
Reference in a new issue