Revert "Add projectHistoryId to updates"

This commit is contained in:
Hayden Faulds
2018-04-23 11:41:29 +01:00
committed by GitHub
parent 9629d0a11e
commit 3cc20d6311
17 changed files with 115 additions and 160 deletions
@@ -25,7 +25,6 @@ describe "DocumentManager", ->
"./UpdateManager": @UpdateManager = {}
"./RangesManager": @RangesManager = {}
@project_id = "project-id-123"
@projectHistoryId = "history-id-123"
@doc_id = "doc-id-123"
@user_id = 1234
@callback = sinon.stub()
@@ -112,7 +111,7 @@ describe "DocumentManager", ->
describe "getDocAndRecentOps", ->
describe "with a previous version specified", ->
beforeEach ->
@DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname, @projectHistoryId)
@DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname)
@RedisManager.getPreviousDocOps = sinon.stub().callsArgWith(3, null, @ops)
@DocumentManager.getDocAndRecentOps @project_id, @doc_id, @fromVersion, @callback
@@ -127,14 +126,14 @@ describe "DocumentManager", ->
.should.equal true
it "should call the callback with the doc info", ->
@callback.calledWith(null, @lines, @version, @ops, @ranges, @pathname, @projectHistoryId).should.equal true
@callback.calledWith(null, @lines, @version, @ops, @ranges, @pathname).should.equal true
it "should time the execution", ->
@Metrics.Timer::done.called.should.equal true
describe "with no previous version specified", ->
beforeEach ->
@DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname, @projectHistoryId)
@DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname)
@RedisManager.getPreviousDocOps = sinon.stub().callsArgWith(3, null, @ops)
@DocumentManager.getDocAndRecentOps @project_id, @doc_id, -1, @callback
@@ -147,7 +146,7 @@ describe "DocumentManager", ->
@RedisManager.getPreviousDocOps.called.should.equal false
it "should call the callback with the doc info", ->
@callback.calledWith(null, @lines, @version, [], @ranges, @pathname, @projectHistoryId).should.equal true
@callback.calledWith(null, @lines, @version, [], @ranges, @pathname).should.equal true
it "should time the execution", ->
@Metrics.Timer::done.called.should.equal true
@@ -155,7 +154,7 @@ describe "DocumentManager", ->
describe "getDoc", ->
describe "when the doc exists in Redis", ->
beforeEach ->
@RedisManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname, @projectHistoryId, @unflushedTime)
@RedisManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname, @unflushedTime)
@DocumentManager.getDoc @project_id, @doc_id, @callback
it "should get the doc from Redis", ->
@@ -164,7 +163,7 @@ describe "DocumentManager", ->
.should.equal true
it "should call the callback with the doc info", ->
@callback.calledWith(null, @lines, @version, @ranges, @pathname, @projectHistoryId, @unflushedTime, true).should.equal true
@callback.calledWith(null, @lines, @version, @ranges, @pathname, @unflushedTime, true).should.equal true
it "should time the execution", ->
@Metrics.Timer::done.called.should.equal true
@@ -172,7 +171,7 @@ describe "DocumentManager", ->
describe "when the doc does not exist in Redis", ->
beforeEach ->
@RedisManager.getDoc = sinon.stub().callsArgWith(2, null, null, null, null, null, null)
@PersistenceManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname, @projectHistoryId)
@PersistenceManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname)
@RedisManager.putDocInMemory = sinon.stub().yields()
@DocumentManager.getDoc @project_id, @doc_id, @callback
@@ -188,11 +187,11 @@ describe "DocumentManager", ->
it "should set the doc in Redis", ->
@RedisManager.putDocInMemory
.calledWith(@project_id, @doc_id, @lines, @version, @ranges, @pathname, @projectHistoryId)
.calledWith(@project_id, @doc_id, @lines, @version, @ranges, @pathname)
.should.equal true
it "should call the callback with the doc info", ->
@callback.calledWith(null, @lines, @version, @ranges, @pathname, @projectHistoryId, null, false).should.equal true
@callback.calledWith(null, @lines, @version, @ranges, @pathname, null, false).should.equal true
it "should time the execution", ->
@Metrics.Timer::done.called.should.equal true
@@ -203,7 +202,7 @@ describe "DocumentManager", ->
@beforeLines = ["before", "lines"]
@afterLines = ["after", "lines"]
@ops = [{ i: "foo", p: 4 }, { d: "bar", p: 42 }]
@DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @beforeLines, @version, @ranges, @pathname, @projectHistoryId, @unflushedTime, true)
@DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @beforeLines, @version, @ranges, @pathname, @unflushedTime, true)
@DiffCodec.diffAsShareJsOp = sinon.stub().callsArgWith(2, null, @ops)
@UpdateManager.applyUpdate = sinon.stub().callsArgWith(3, null)
@DocumentManager.flushDocIfLoaded = sinon.stub().callsArg(2)
@@ -403,7 +402,7 @@ describe "DocumentManager", ->
describe "when the doc is in Redis", ->
describe "and has changes to be flushed", ->
beforeEach ->
@DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @projectHistoryId, @pathname, Date.now() - 1e9, true)
@DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname, Date.now() - 1e9, true)
@DocumentManager.getDocAndFlushIfOld @project_id, @doc_id, @callback
it "should get the doc", ->
@@ -460,11 +459,11 @@ describe "DocumentManager", ->
describe "successfully", ->
beforeEach ->
@DocumentManager.renameDoc @project_id, @doc_id, @user_id, @update, @projectHistoryId, @callback
@DocumentManager.renameDoc @project_id, @doc_id, @user_id, @update, @callback
it "should rename the document", ->
@RedisManager.renameDoc
.calledWith(@project_id, @doc_id, @user_id, @update, @projectHistoryId)
.calledWith(@project_id, @doc_id, @user_id, @update)
.should.equal true
it "should call the callback", ->
@@ -473,7 +472,7 @@ describe "DocumentManager", ->
describe "resyncDocContents", ->
describe "when doc is loaded in redis", ->
beforeEach ->
@RedisManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname, @projectHistoryId)
@RedisManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname)
@ProjectHistoryRedisManager.queueResyncDocContent = sinon.stub()
@DocumentManager.resyncDocContents @project_id, @doc_id, @callback
@@ -484,13 +483,13 @@ describe "DocumentManager", ->
it "queues a resync doc content update", ->
@ProjectHistoryRedisManager.queueResyncDocContent
.calledWith(@project_id, @projectHistoryId, @doc_id, @lines, @version, @pathname, @callback)
.calledWith(@project_id, @doc_id, @lines, @version, @pathname, @callback)
.should.equal true
describe "when doc is not loaded in redis", ->
beforeEach ->
@RedisManager.getDoc = sinon.stub().callsArgWith(2, null)
@PersistenceManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname, @projectHistoryId)
@PersistenceManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname)
@ProjectHistoryRedisManager.queueResyncDocContent = sinon.stub()
@DocumentManager.resyncDocContents @project_id, @doc_id, @callback
@@ -506,5 +505,5 @@ describe "DocumentManager", ->
it "queues a resync doc content update", ->
@ProjectHistoryRedisManager.queueResyncDocContent
.calledWith(@project_id, @projectHistoryId, @doc_id, @lines, @version, @pathname, @callback)
.calledWith(@project_id, @doc_id, @lines, @version, @pathname, @callback)
.should.equal true
@@ -164,7 +164,6 @@ describe "HistoryManager", ->
describe "resyncProjectHistory", ->
beforeEach ->
@projectHistoryId = 'history-id-1234'
@docs = [
doc: @doc_id
path: 'main.tex'
@@ -176,11 +175,11 @@ describe "HistoryManager", ->
]
@ProjectHistoryRedisManager.queueResyncProjectStructure = sinon.stub().yields()
@DocumentManager.resyncDocContentsWithLock = sinon.stub().yields()
@HistoryManager.resyncProjectHistory @project_id, @projectHistoryId, @docs, @files, @callback
@HistoryManager.resyncProjectHistory @project_id, @docs, @files, @callback
it "should queue a project structure reync", ->
@ProjectHistoryRedisManager.queueResyncProjectStructure
.calledWith(@project_id, @projectHistoryId, @docs, @files)
.calledWith(@project_id, @docs, @files)
.should.equal true
it "should queue doc content reyncs", ->
@@ -509,24 +509,23 @@ describe "HttpController", ->
describe "updateProject", ->
beforeEach ->
@projectHistoryId = "history-id-123"
@userId = "user-id-123"
@docUpdates = sinon.stub()
@fileUpdates = sinon.stub()
@version = 1234567
@req =
body: {@projectHistoryId, @userId, @docUpdates, @fileUpdates, @version}
body: {@userId, @docUpdates, @fileUpdates, @version}
params:
project_id: @project_id
describe "successfully", ->
beforeEach ->
@ProjectManager.updateProjectWithLocks = sinon.stub().callsArgWith(6)
@ProjectManager.updateProjectWithLocks = sinon.stub().callsArgWith(5)
@HttpController.updateProject(@req, @res, @next)
it "should accept the change", ->
@ProjectManager.updateProjectWithLocks
.calledWith(@project_id, @projectHistoryId, @userId, @docUpdates, @fileUpdates, @version)
.calledWith(@project_id, @userId, @docUpdates, @fileUpdates, @version)
.should.equal true
it "should return a successful No Content response", ->
@@ -539,7 +538,7 @@ describe "HttpController", ->
describe "when an errors occurs", ->
beforeEach ->
@ProjectManager.updateProjectWithLocks = sinon.stub().callsArgWith(6, new Error("oops"))
@ProjectManager.updateProjectWithLocks = sinon.stub().callsArgWith(5, new Error("oops"))
@HttpController.updateProject(@req, @res, @next)
it "should call next with the error", ->
@@ -549,24 +548,23 @@ describe "HttpController", ->
describe "resyncProjectHistory", ->
beforeEach ->
@projectHistoryId = "history-id-123"
@docs = sinon.stub()
@files = sinon.stub()
@fileUpdates = sinon.stub()
@req =
body:
{@projectHistoryId, @docs, @files}
{@docs, @files}
params:
project_id: @project_id
describe "successfully", ->
beforeEach ->
@HistoryManager.resyncProjectHistory = sinon.stub().callsArgWith(4)
@HistoryManager.resyncProjectHistory = sinon.stub().callsArg(3)
@HttpController.resyncProjectHistory(@req, @res, @next)
it "should accept the change", ->
@HistoryManager.resyncProjectHistory
.calledWith(@project_id, @projectHistoryId, @docs, @files)
.calledWith(@project_id, @docs, @files)
.should.equal true
it "should return a successful No Content response", ->
@@ -576,7 +574,7 @@ describe "HttpController", ->
describe "when an errors occurs", ->
beforeEach ->
@HistoryManager.resyncProjectHistory = sinon.stub().callsArgWith(4, new Error("oops"))
@HistoryManager.resyncProjectHistory = sinon.stub().callsArgWith(3, new Error("oops"))
@HttpController.resyncProjectHistory(@req, @res, @next)
it "should call next with the error", ->
@@ -17,7 +17,6 @@ describe "PersistenceManager", ->
done: sinon.stub()
"logger-sharelatex": @logger = {log: sinon.stub(), err: sinon.stub()}
@project_id = "project-id-123"
@projectHistoryId = "history-id-123"
@doc_id = "doc-id-123"
@lines = ["one", "two", "three"]
@version = 42
@@ -37,7 +36,6 @@ describe "PersistenceManager", ->
version: @version,
ranges: @ranges
pathname: @pathname,
projectHistoryId: @projectHistoryId
}
describe "with a successful response from the web api", ->
@@ -62,9 +60,7 @@ describe "PersistenceManager", ->
.should.equal true
it "should call the callback with the doc lines, version and ranges", ->
@callback
.calledWith(null, @lines, @version, @ranges, @pathname, @projectHistoryId)
.should.equal true
@callback.calledWith(null, @lines, @version, @ranges, @pathname).should.equal true
it "should time the execution", ->
@Metrics.Timer::done.called.should.equal true
@@ -8,7 +8,6 @@ tk = require "timekeeper"
describe "ProjectHistoryRedisManager", ->
beforeEach ->
@project_id = "project-id-123"
@projectHistoryId = "history-id-123"
@user_id = "user-id-123"
@callback = sinon.stub()
@rclient = {}
@@ -51,10 +50,9 @@ describe "ProjectHistoryRedisManager", ->
@rawUpdate =
pathname: @pathname = '/old'
newPathname: @newPathname = '/new'
version: @version = 2
@ProjectHistoryRedisManager.queueOps = sinon.stub()
@ProjectHistoryRedisManager.queueRenameEntity @project_id, @projectHistoryId, 'file', @file_id, @user_id, @rawUpdate, @callback
@ProjectHistoryRedisManager.queueRenameEntity @project_id, 'file', @file_id, @user_id, @rawUpdate, @callback
it "should queue an update", ->
update =
@@ -63,8 +61,6 @@ describe "ProjectHistoryRedisManager", ->
meta:
user_id: @user_id
ts: new Date()
version: @version
projectHistoryId: @projectHistoryId
file: @file_id
@ProjectHistoryRedisManager.queueOps
@@ -79,11 +75,10 @@ describe "ProjectHistoryRedisManager", ->
@rawUpdate =
pathname: @pathname = '/old'
docLines: @docLines = 'a\nb'
version: @version = 2
url: @url = 'filestore.example.com'
@ProjectHistoryRedisManager.queueOps = sinon.stub()
@ProjectHistoryRedisManager.queueAddEntity @project_id, @projectHistoryId, 'doc', @doc_id, @user_id, @rawUpdate, @callback
@ProjectHistoryRedisManager.queueAddEntity @project_id, 'doc', @doc_id, @user_id, @rawUpdate, @callback
it "should queue an update", ->
update =
@@ -93,8 +88,6 @@ describe "ProjectHistoryRedisManager", ->
meta:
user_id: @user_id
ts: new Date()
version: @version
projectHistoryId: @projectHistoryId
doc: @doc_id
@ProjectHistoryRedisManager.queueOps
@@ -18,7 +18,6 @@ describe "ProjectManager", ->
done: sinon.stub()
@project_id = "project-id-123"
@projectHistoryId = 'history-id-123'
@user_id = "user-id-123"
@version = 1234567
@HistoryManager.shouldFlushHistoryOps = sinon.stub().returns(false)
@@ -28,6 +27,7 @@ describe "ProjectManager", ->
describe "updateProjectWithLocks", ->
describe "rename operations", ->
beforeEach ->
@firstDocUpdate =
id: 1
pathname: 'foo'
@@ -47,22 +47,22 @@ describe "ProjectManager", ->
describe "successfully", ->
beforeEach ->
@ProjectManager.updateProjectWithLocks @project_id, @projectHistoryId, @user_id, @docUpdates, @fileUpdates, @version, @callback
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback
it "should rename the docs in the updates", ->
firstDocUpdateWithVersion = _.extend({}, @firstDocUpdate, {version: "#{@version}.0"})
secondDocUpdateWithVersion = _.extend({}, @secondDocUpdate, {version: "#{@version}.1"})
@DocumentManager.renameDocWithLock
.calledWith(@project_id, @firstDocUpdate.id, @user_id, firstDocUpdateWithVersion, @projectHistoryId)
.calledWith(@project_id, @firstDocUpdate.id, @user_id, firstDocUpdateWithVersion)
.should.equal true
@DocumentManager.renameDocWithLock
.calledWith(@project_id, @secondDocUpdate.id, @user_id, secondDocUpdateWithVersion, @projectHistoryId)
.calledWith(@project_id, @secondDocUpdate.id, @user_id, secondDocUpdateWithVersion)
.should.equal true
it "should rename the files in the updates", ->
firstFileUpdateWithVersion = _.extend({}, @firstFileUpdate, {version: "#{@version}.2"})
@ProjectHistoryRedisManager.queueRenameEntity
.calledWith(@project_id, @projectHistoryId, 'file', @firstFileUpdate.id, @user_id, firstFileUpdateWithVersion)
.calledWith(@project_id, 'file', @firstFileUpdate.id, @user_id, firstFileUpdateWithVersion)
.should.equal true
it "should not flush the history", ->
@@ -77,7 +77,7 @@ describe "ProjectManager", ->
beforeEach ->
@error = new Error('error')
@DocumentManager.renameDocWithLock = sinon.stub().yields(@error)
@ProjectManager.updateProjectWithLocks @project_id, @projectHistoryId, @user_id, @docUpdates, @fileUpdates, @version, @callback
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback
it "should call the callback with the error", ->
@callback.calledWith(@error).should.equal true
@@ -86,7 +86,7 @@ describe "ProjectManager", ->
beforeEach ->
@error = new Error('error')
@ProjectHistoryRedisManager.queueRenameEntity = sinon.stub().yields(@error)
@ProjectManager.updateProjectWithLocks @project_id, @projectHistoryId, @user_id, @docUpdates, @fileUpdates, @version, @callback
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback
it "should call the callback with the error", ->
@callback.calledWith(@error).should.equal true
@@ -94,7 +94,7 @@ describe "ProjectManager", ->
describe "with enough ops to flush", ->
beforeEach ->
@HistoryManager.shouldFlushHistoryOps = sinon.stub().returns(true)
@ProjectManager.updateProjectWithLocks @project_id, @projectHistoryId, @user_id, @docUpdates, @fileUpdates, @version, @callback
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback
it "should flush the history", ->
@HistoryManager.flushProjectChangesAsync
@@ -121,26 +121,26 @@ describe "ProjectManager", ->
describe "successfully", ->
beforeEach ->
@ProjectManager.updateProjectWithLocks @project_id, @projectHistoryId, @user_id, @docUpdates, @fileUpdates, @version, @callback
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback
it "should add the docs in the updates", ->
firstDocUpdateWithVersion = _.extend({}, @firstDocUpdate, {version: "#{@version}.0"})
secondDocUpdateWithVersion = _.extend({}, @secondDocUpdate, {version: "#{@version}.1"})
@ProjectHistoryRedisManager.queueAddEntity.getCall(0)
.calledWith(@project_id, @projectHistoryId, 'doc', @firstDocUpdate.id, @user_id, firstDocUpdateWithVersion)
.calledWith(@project_id, 'doc', @firstDocUpdate.id, @user_id, firstDocUpdateWithVersion)
.should.equal true
@ProjectHistoryRedisManager.queueAddEntity.getCall(1)
.calledWith(@project_id, @projectHistoryId, 'doc', @secondDocUpdate.id, @user_id, secondDocUpdateWithVersion)
.calledWith(@project_id, 'doc', @secondDocUpdate.id, @user_id, secondDocUpdateWithVersion)
.should.equal true
it "should add the files in the updates", ->
firstFileUpdateWithVersion = _.extend({}, @firstFileUpdate, {version: "#{@version}.2"})
secondFileUpdateWithVersion = _.extend({}, @secondFileUpdate, {version: "#{@version}.3"})
@ProjectHistoryRedisManager.queueAddEntity.getCall(2)
.calledWith(@project_id, @projectHistoryId, 'file', @firstFileUpdate.id, @user_id, firstFileUpdateWithVersion)
.calledWith(@project_id, 'file', @firstFileUpdate.id, @user_id, firstFileUpdateWithVersion)
.should.equal true
@ProjectHistoryRedisManager.queueAddEntity.getCall(3)
.calledWith(@project_id, @projectHistoryId, 'file', @secondFileUpdate.id, @user_id, secondFileUpdateWithVersion)
.calledWith(@project_id, 'file', @secondFileUpdate.id, @user_id, secondFileUpdateWithVersion)
.should.equal true
it "should not flush the history", ->
@@ -155,7 +155,7 @@ describe "ProjectManager", ->
beforeEach ->
@error = new Error('error')
@ProjectHistoryRedisManager.queueAddEntity = sinon.stub().yields(@error)
@ProjectManager.updateProjectWithLocks @project_id, @projectHistoryId, @user_id, @docUpdates, @fileUpdates, @version, @callback
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback
it "should call the callback with the error", ->
@callback.calledWith(@error).should.equal true
@@ -164,7 +164,7 @@ describe "ProjectManager", ->
beforeEach ->
@error = new Error('error')
@ProjectHistoryRedisManager.queueAddEntity = sinon.stub().yields(@error)
@ProjectManager.updateProjectWithLocks @project_id, @projectHistoryId, @user_id, @docUpdates, @fileUpdates, @version, @callback
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback
it "should call the callback with the error", ->
@callback.calledWith(@error).should.equal true
@@ -172,7 +172,7 @@ describe "ProjectManager", ->
describe "with enough ops to flush", ->
beforeEach ->
@HistoryManager.shouldFlushHistoryOps = sinon.stub().returns(true)
@ProjectManager.updateProjectWithLocks @project_id, @projectHistoryId, @user_id, @docUpdates, @fileUpdates, @version, @callback
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback
it "should flush the history", ->
@HistoryManager.flushProjectChangesAsync
@@ -33,7 +33,6 @@ describe "RedisManager", ->
docsInProject: ({project_id}) -> "DocsIn:#{project_id}"
ranges: ({doc_id}) -> "Ranges:#{doc_id}"
pathname: ({doc_id}) -> "Pathname:#{doc_id}"
projectHistoryId: ({doc_id}) -> "ProjectHistoryId:#{doc_id}"
projectState: ({project_id}) -> "ProjectState:#{project_id}"
unflushedTime: ({doc_id}) -> "UnflushedTime:#{doc_id}"
history:
@@ -60,7 +59,6 @@ describe "RedisManager", ->
@doc_id = "doc-id-123"
@project_id = "project-id-123"
@projectHistoryId = "history-id-123"
@callback = sinon.stub()
describe "getDoc", ->
@@ -74,7 +72,7 @@ describe "RedisManager", ->
@unflushed_time = 12345
@pathname = '/a/b/c.tex'
@multi.get = sinon.stub()
@multi.exec = sinon.stub().callsArgWith(0, null, [@jsonlines, @version, @hash, @project_id, @json_ranges, @pathname, @projectHistoryId, @unflushed_time])
@multi.exec = sinon.stub().callsArgWith(0, null, [@jsonlines, @version, @hash, @project_id, @json_ranges, @pathname, @unflushed_time])
@rclient.sadd = sinon.stub().yields(null, 0)
describe "successfully", ->
@@ -111,11 +109,6 @@ describe "RedisManager", ->
.calledWith("Pathname:#{@doc_id}")
.should.equal true
it "should get the projectHistoryId", ->
@multi.get
.calledWith("ProjectHistoryId:#{@doc_id}")
.should.equal true
it "should check if the document is in the DocsIn set", ->
@rclient.sadd
.calledWith("DocsIn:#{@project_id}")
@@ -123,7 +116,7 @@ describe "RedisManager", ->
it 'should return the document', ->
@callback
.calledWithExactly(null, @lines, @version, @ranges, @pathname, @projectHistoryId, @unflushed_time)
.calledWithExactly(null, @lines, @version, @ranges, @pathname, @unflushed_time)
.should.equal true
it 'should not log any errors', ->
@@ -132,7 +125,7 @@ describe "RedisManager", ->
describe "when the document is not present", ->
beforeEach ->
@multi.exec = sinon.stub().callsArgWith(0, null, [null, null, null, null, null, null, null, null])
@multi.exec = sinon.stub().callsArgWith(0, null, [null, null, null, null, null, null, null])
@rclient.sadd = sinon.stub().yields()
@RedisManager.getDoc @project_id, @doc_id, @callback
@@ -143,7 +136,7 @@ describe "RedisManager", ->
it 'should return an empty result', ->
@callback
.calledWithExactly(null, null, 0, {}, null, null, null)
.calledWithExactly(null, null, 0, {}, null, null)
.should.equal true
it 'should not log any errors', ->
@@ -161,7 +154,7 @@ describe "RedisManager", ->
it 'should return the document', ->
@callback
.calledWithExactly(null, @lines, @version, @ranges, @pathname, @projectHistoryId, @unflushed_time)
.calledWithExactly(null, @lines, @version, @ranges, @pathname, @unflushed_time)
.should.equal true
describe "with a corrupted document", ->
@@ -539,7 +532,7 @@ describe "RedisManager", ->
describe "with non-empty ranges", ->
beforeEach (done) ->
@RedisManager.putDocInMemory @project_id, @doc_id, @lines, @version, @ranges, @pathname, @projectHistoryId, done
@RedisManager.putDocInMemory @project_id, @doc_id, @lines, @version, @ranges, @pathname, done
it "should set the lines", ->
@multi.eval
@@ -571,11 +564,6 @@ describe "RedisManager", ->
.calledWith("Pathname:#{@doc_id}", @pathname)
.should.equal true
it "should set the projectHistoryId for the doc", ->
@multi.set
.calledWith("ProjectHistoryId:#{@doc_id}", @projectHistoryId)
.should.equal true
it "should add the doc_id to the project set", ->
@rclient.sadd
.calledWith("DocsIn:#{@project_id}", @doc_id)
@@ -587,7 +575,7 @@ describe "RedisManager", ->
describe "with empty ranges", ->
beforeEach (done) ->
@RedisManager.putDocInMemory @project_id, @doc_id, @lines, @version, {}, @pathname, @projectHistoryId, done
@RedisManager.putDocInMemory @project_id, @doc_id, @lines, @version, {}, @pathname, done
it "should delete the ranges key", ->
@multi.del
@@ -602,7 +590,7 @@ describe "RedisManager", ->
describe "with a corrupted write", ->
beforeEach (done) ->
@multi.exec = sinon.stub().callsArgWith(0, null, ["INVALID-HASH-VALUE"])
@RedisManager.putDocInMemory @project_id, @doc_id, @lines, @version, @ranges, @pathname, @projectHistoryId, done
@RedisManager.putDocInMemory @project_id, @doc_id, @lines, @version, @ranges, @pathname, done
it 'should log a hash error', ->
@logger.error.calledWith()
@@ -612,7 +600,7 @@ describe "RedisManager", ->
beforeEach ->
@_stringify = JSON.stringify
@JSON.stringify = () -> return '["bad bytes! \u0000 <- here"]'
@RedisManager.putDocInMemory @project_id, @doc_id, @lines, @version, @ranges, @pathname, @projectHistoryId, @callback
@RedisManager.putDocInMemory @project_id, @doc_id, @lines, @version, @ranges, @pathname, @callback
afterEach ->
@JSON.stringify = @_stringify
@@ -626,7 +614,7 @@ describe "RedisManager", ->
describe "with ranges that are too big", ->
beforeEach ->
@RedisManager._serializeRanges = sinon.stub().yields(new Error("ranges are too large"))
@RedisManager.putDocInMemory @project_id, @doc_id, @lines, @version, @ranges, @pathname, @projectHistoryId, @callback
@RedisManager.putDocInMemory @project_id, @doc_id, @lines, @version, @ranges, @pathname, @callback
it 'should log an error', ->
@logger.error.called.should.equal true
@@ -676,11 +664,6 @@ describe "RedisManager", ->
.calledWith("Pathname:#{@doc_id}")
.should.equal true
it "should delete the pathname for the doc", ->
@multi.del
.calledWith("ProjectHistoryId:#{@doc_id}")
.should.equal true
describe "clearProjectState", ->
beforeEach (done) ->
@rclient.del = sinon.stub().callsArg(1)
@@ -704,7 +687,7 @@ describe "RedisManager", ->
beforeEach ->
@RedisManager.getDoc = sinon.stub().callsArgWith(2, null, 'lines', 'version')
@ProjectHistoryRedisManager.queueRenameEntity = sinon.stub().yields()
@RedisManager.renameDoc @project_id, @doc_id, @userId, @update, @projectHistoryId, @callback
@RedisManager.renameDoc @project_id, @doc_id, @userId, @update, @callback
it "update the cached pathname", ->
@rclient.set
@@ -713,19 +696,19 @@ describe "RedisManager", ->
it "should queue an update", ->
@ProjectHistoryRedisManager.queueRenameEntity
.calledWithExactly(@project_id, @projectHistoryId, 'doc', @doc_id, @userId, @update, @callback)
.calledWithExactly(@project_id, 'doc', @doc_id, @userId, @update, @callback)
.should.equal true
describe "the document is not cached in redis", ->
beforeEach ->
@RedisManager.getDoc = sinon.stub().callsArgWith(2, null, null, null)
@ProjectHistoryRedisManager.queueRenameEntity = sinon.stub().yields()
@RedisManager.renameDoc @project_id, @doc_id, @userId, @update, @projectHistoryId, @callback
@RedisManager.renameDoc @project_id, @doc_id, @userId, @update, @callback
it "does not update the cached pathname", ->
@rclient.set.called.should.equal false
it "should queue an update", ->
@ProjectHistoryRedisManager.queueRenameEntity
.calledWithExactly(@project_id, @projectHistoryId, 'doc', @doc_id, @userId, @update, @callback)
.calledWithExactly(@project_id, 'doc', @doc_id, @userId, @update, @callback)
.should.equal true
@@ -7,7 +7,6 @@ SandboxedModule = require('sandboxed-module')
describe "UpdateManager", ->
beforeEach ->
@project_id = "project-id-123"
@projectHistoryId = "history-id-123"
@doc_id = "document-id-123"
@callback = sinon.stub()
@UpdateManager = SandboxedModule.require modulePath, requires:
@@ -168,7 +167,7 @@ describe "UpdateManager", ->
@doc_ops_length = sinon.stub()
@project_ops_length = sinon.stub()
@pathname = '/a/b/c.tex'
@DocumentManager.getDoc = sinon.stub().yields(null, @lines, @version, @ranges, @pathname, @projectHistoryId)
@DocumentManager.getDoc = sinon.stub().yields(null, @lines, @version, @ranges, @pathname)
@RangesManager.applyUpdate = sinon.stub().yields(null, @updated_ranges)
@ShareJsUpdateManager.applyUpdate = sinon.stub().yields(null, @updatedDocLines, @version, @appliedOps)
@RedisManager.updateDocument = sinon.stub().yields(null, @doc_ops_length, @project_ops_length)
@@ -197,7 +196,7 @@ describe "UpdateManager", ->
it "should add metadata to the ops" , ->
@UpdateManager._addProjectHistoryMetadataToOps
.calledWith(@appliedOps, @pathname, @projectHistoryId, @lines)
.calledWith(@appliedOps, @pathname, @lines)
.should.equal true
it "should push the applied ops into the history queue", ->
@@ -240,7 +239,7 @@ describe "UpdateManager", ->
@callback.calledWith(@error).should.equal true
describe "_addProjectHistoryMetadataToOps", ->
it "should add projectHistoryId, pathname and doc_length metadata to the ops", ->
it "should add pathname and doc_length metadata to the ops", ->
lines = [
'some'
'test'
@@ -251,23 +250,20 @@ describe "UpdateManager", ->
{ v: 45, op: [{d: "qux", p: 4}, { i: "bazbaz", p: 14 }] },
{ v: 49, op: [{i: "penguin", p: 18}] }
]
@UpdateManager._addProjectHistoryMetadataToOps(appliedOps, @pathname, @projectHistoryId, lines)
@UpdateManager._addProjectHistoryMetadataToOps(appliedOps, @pathname, lines)
appliedOps.should.deep.equal [{
projectHistoryId: @projectHistoryId
v: 42
op: [{i: "foo", p: 4}, { i: "bar", p: 6 }]
meta:
pathname: @pathname
doc_length: 14
}, {
projectHistoryId: @projectHistoryId
v: 45
op: [{d: "qux", p: 4}, { i: "bazbaz", p: 14 }]
meta:
pathname: @pathname
doc_length: 20 # 14 + 'foo' + 'bar'
}, {
projectHistoryId: @projectHistoryId
v: 49
op: [{i: "penguin", p: 18}]
meta: