2014-02-12 05:40:42 -05:00
|
|
|
sinon = require('sinon')
|
|
|
|
chai = require('chai')
|
|
|
|
should = chai.should()
|
|
|
|
modulePath = "../../../../app/js/UpdateManager.js"
|
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
|
|
|
|
describe "UpdateManager", ->
|
|
|
|
beforeEach ->
|
|
|
|
@project_id = "project-id-123"
|
2018-04-23 07:08:04 -04:00
|
|
|
@projectHistoryId = "history-id-123"
|
2014-02-12 05:40:42 -05:00
|
|
|
@doc_id = "document-id-123"
|
|
|
|
@callback = sinon.stub()
|
|
|
|
@UpdateManager = SandboxedModule.require modulePath, requires:
|
|
|
|
"./LockManager" : @LockManager = {}
|
|
|
|
"./RedisManager" : @RedisManager = {}
|
2017-05-02 10:38:33 -04:00
|
|
|
"./RealTimeRedisManager" : @RealTimeRedisManager = {}
|
2014-02-12 05:40:42 -05:00
|
|
|
"./ShareJsUpdateManager" : @ShareJsUpdateManager = {}
|
2016-12-01 13:06:33 -05:00
|
|
|
"./HistoryManager" : @HistoryManager = {}
|
2014-02-12 05:40:42 -05:00
|
|
|
"logger-sharelatex": @logger = { log: sinon.stub() }
|
|
|
|
"./Metrics": @Metrics =
|
|
|
|
Timer: class Timer
|
|
|
|
done: sinon.stub()
|
2017-10-05 08:45:29 -04:00
|
|
|
"settings-sharelatex": @Settings = {}
|
2016-12-01 13:06:33 -05:00
|
|
|
"./DocumentManager": @DocumentManager = {}
|
2016-12-08 07:31:43 -05:00
|
|
|
"./RangesManager": @RangesManager = {}
|
2019-04-11 08:25:03 -04:00
|
|
|
"./SnapshotManager": @SnapshotManager = {}
|
2017-06-08 11:43:27 -04:00
|
|
|
"./Profiler": class Profiler
|
|
|
|
log: sinon.stub().returns { end: sinon.stub() }
|
|
|
|
end: sinon.stub()
|
2014-02-12 05:40:42 -05:00
|
|
|
|
|
|
|
describe "processOutstandingUpdates", ->
|
|
|
|
beforeEach ->
|
|
|
|
@UpdateManager.fetchAndApplyUpdates = sinon.stub().callsArg(2)
|
|
|
|
@UpdateManager.processOutstandingUpdates @project_id, @doc_id, @callback
|
|
|
|
|
|
|
|
it "should apply the updates", ->
|
|
|
|
@UpdateManager.fetchAndApplyUpdates.calledWith(@project_id, @doc_id).should.equal true
|
|
|
|
|
|
|
|
it "should call the callback", ->
|
|
|
|
@callback.called.should.equal true
|
|
|
|
|
|
|
|
it "should time the execution", ->
|
|
|
|
@Metrics.Timer::done.called.should.equal true
|
|
|
|
|
|
|
|
describe "processOutstandingUpdatesWithLock", ->
|
|
|
|
describe "when the lock is free", ->
|
|
|
|
beforeEach ->
|
2016-04-13 06:59:56 -04:00
|
|
|
@LockManager.tryLock = sinon.stub().callsArgWith(1, null, true, @lockValue = "mock-lock-value")
|
|
|
|
@LockManager.releaseLock = sinon.stub().callsArg(2)
|
2014-02-12 05:40:42 -05:00
|
|
|
@UpdateManager.continueProcessingUpdatesWithLock = sinon.stub().callsArg(2)
|
|
|
|
@UpdateManager.processOutstandingUpdates = sinon.stub().callsArg(2)
|
|
|
|
|
|
|
|
describe "successfully", ->
|
|
|
|
beforeEach ->
|
|
|
|
@UpdateManager.processOutstandingUpdatesWithLock @project_id, @doc_id, @callback
|
|
|
|
|
|
|
|
it "should acquire the lock", ->
|
|
|
|
@LockManager.tryLock.calledWith(@doc_id).should.equal true
|
|
|
|
|
|
|
|
it "should free the lock", ->
|
2016-04-13 06:59:56 -04:00
|
|
|
@LockManager.releaseLock.calledWith(@doc_id, @lockValue).should.equal true
|
2014-02-12 05:40:42 -05:00
|
|
|
|
|
|
|
it "should process the outstanding updates", ->
|
|
|
|
@UpdateManager.processOutstandingUpdates.calledWith(@project_id, @doc_id).should.equal true
|
2017-09-29 07:44:36 -04:00
|
|
|
|
2014-02-12 05:40:42 -05:00
|
|
|
it "should do everything with the lock acquired", ->
|
|
|
|
@UpdateManager.processOutstandingUpdates.calledAfter(@LockManager.tryLock).should.equal true
|
|
|
|
@UpdateManager.processOutstandingUpdates.calledBefore(@LockManager.releaseLock).should.equal true
|
|
|
|
|
|
|
|
it "should continue processing new updates that may have come in", ->
|
|
|
|
@UpdateManager.continueProcessingUpdatesWithLock.calledWith(@project_id, @doc_id).should.equal true
|
2017-09-29 07:44:36 -04:00
|
|
|
|
2014-02-12 05:40:42 -05:00
|
|
|
it "should return the callback", ->
|
|
|
|
@callback.called.should.equal true
|
|
|
|
|
|
|
|
describe "when processOutstandingUpdates returns an error", ->
|
|
|
|
beforeEach ->
|
|
|
|
@UpdateManager.processOutstandingUpdates = sinon.stub().callsArgWith(2, @error = new Error("Something went wrong"))
|
|
|
|
@UpdateManager.processOutstandingUpdatesWithLock @project_id, @doc_id, @callback
|
|
|
|
|
|
|
|
it "should free the lock", ->
|
2016-04-13 06:59:56 -04:00
|
|
|
@LockManager.releaseLock.calledWith(@doc_id, @lockValue).should.equal true
|
2017-09-29 07:44:36 -04:00
|
|
|
|
2014-02-12 05:40:42 -05:00
|
|
|
it "should return the error in the callback", ->
|
|
|
|
@callback.calledWith(@error).should.equal true
|
|
|
|
|
|
|
|
describe "when the lock is taken", ->
|
|
|
|
beforeEach ->
|
|
|
|
@LockManager.tryLock = sinon.stub().callsArgWith(1, null, false)
|
|
|
|
@UpdateManager.processOutstandingUpdates = sinon.stub().callsArg(2)
|
|
|
|
@UpdateManager.processOutstandingUpdatesWithLock @project_id, @doc_id, @callback
|
|
|
|
|
|
|
|
it "should return the callback", ->
|
|
|
|
@callback.called.should.equal true
|
|
|
|
|
|
|
|
it "should not process the updates", ->
|
|
|
|
@UpdateManager.processOutstandingUpdates.called.should.equal false
|
2017-09-29 07:44:36 -04:00
|
|
|
|
2014-02-12 05:40:42 -05:00
|
|
|
describe "continueProcessingUpdatesWithLock", ->
|
|
|
|
describe "when there are outstanding updates", ->
|
|
|
|
beforeEach ->
|
2017-05-02 10:38:33 -04:00
|
|
|
@RealTimeRedisManager.getUpdatesLength = sinon.stub().callsArgWith(1, null, 3)
|
2014-02-12 05:40:42 -05:00
|
|
|
@UpdateManager.processOutstandingUpdatesWithLock = sinon.stub().callsArg(2)
|
|
|
|
@UpdateManager.continueProcessingUpdatesWithLock @project_id, @doc_id, @callback
|
|
|
|
|
|
|
|
it "should process the outstanding updates", ->
|
|
|
|
@UpdateManager.processOutstandingUpdatesWithLock.calledWith(@project_id, @doc_id).should.equal true
|
|
|
|
|
|
|
|
it "should return the callback", ->
|
|
|
|
@callback.called.should.equal true
|
|
|
|
|
|
|
|
describe "when there are no outstanding updates", ->
|
|
|
|
beforeEach ->
|
2017-05-02 10:38:33 -04:00
|
|
|
@RealTimeRedisManager.getUpdatesLength = sinon.stub().callsArgWith(1, null, 0)
|
2014-02-12 05:40:42 -05:00
|
|
|
@UpdateManager.processOutstandingUpdatesWithLock = sinon.stub().callsArg(2)
|
|
|
|
@UpdateManager.continueProcessingUpdatesWithLock @project_id, @doc_id, @callback
|
|
|
|
|
|
|
|
it "should not try to process the outstanding updates", ->
|
|
|
|
@UpdateManager.processOutstandingUpdatesWithLock.called.should.equal false
|
|
|
|
|
|
|
|
it "should return the callback", ->
|
|
|
|
@callback.called.should.equal true
|
|
|
|
|
|
|
|
describe "fetchAndApplyUpdates", ->
|
|
|
|
describe "with updates", ->
|
|
|
|
beforeEach ->
|
|
|
|
@updates = [{p: 1, t: "foo"}]
|
|
|
|
@updatedDocLines = ["updated", "lines"]
|
|
|
|
@version = 34
|
2017-05-02 10:38:33 -04:00
|
|
|
@RealTimeRedisManager.getPendingUpdatesForDoc = sinon.stub().callsArgWith(1, null, @updates)
|
2016-09-09 06:01:14 -04:00
|
|
|
@UpdateManager.applyUpdate = sinon.stub().callsArgWith(3, null, @updatedDocLines, @version)
|
2014-02-12 05:40:42 -05:00
|
|
|
@UpdateManager.fetchAndApplyUpdates @project_id, @doc_id, @callback
|
|
|
|
|
|
|
|
it "should get the pending updates", ->
|
2017-05-02 10:38:33 -04:00
|
|
|
@RealTimeRedisManager.getPendingUpdatesForDoc.calledWith(@doc_id).should.equal true
|
2014-02-12 05:40:42 -05:00
|
|
|
|
|
|
|
it "should apply the updates", ->
|
2016-09-09 06:01:14 -04:00
|
|
|
for update in @updates
|
|
|
|
@UpdateManager.applyUpdate
|
|
|
|
.calledWith(@project_id, @doc_id, update)
|
|
|
|
.should.equal true
|
2017-09-29 07:44:36 -04:00
|
|
|
|
2014-02-12 05:40:42 -05:00
|
|
|
it "should call the callback", ->
|
|
|
|
@callback.called.should.equal true
|
|
|
|
|
|
|
|
describe "when there are no updates", ->
|
|
|
|
beforeEach ->
|
|
|
|
@updates = []
|
2017-05-02 10:38:33 -04:00
|
|
|
@RealTimeRedisManager.getPendingUpdatesForDoc = sinon.stub().callsArgWith(1, null, @updates)
|
2016-09-09 06:01:14 -04:00
|
|
|
@UpdateManager.applyUpdate = sinon.stub()
|
2014-02-12 05:40:42 -05:00
|
|
|
@RedisManager.setDocument = sinon.stub()
|
|
|
|
@UpdateManager.fetchAndApplyUpdates @project_id, @doc_id, @callback
|
|
|
|
|
2016-09-09 06:01:14 -04:00
|
|
|
it "should not call applyUpdate", ->
|
|
|
|
@UpdateManager.applyUpdate.called.should.equal false
|
2014-02-12 05:40:42 -05:00
|
|
|
|
|
|
|
it "should call the callback", ->
|
|
|
|
@callback.called.should.equal true
|
2017-09-29 07:44:36 -04:00
|
|
|
|
2016-09-09 06:01:14 -04:00
|
|
|
describe "applyUpdate", ->
|
2014-02-12 05:40:42 -05:00
|
|
|
beforeEach ->
|
2019-04-22 20:02:48 -04:00
|
|
|
@updateMeta = { user_id: 'last-author-fake-id' }
|
|
|
|
@update = {op: [{p: 42, i: "foo"}], meta: @updateMeta}
|
2014-02-12 05:40:42 -05:00
|
|
|
@updatedDocLines = ["updated", "lines"]
|
|
|
|
@version = 34
|
2016-12-01 13:19:47 -05:00
|
|
|
@lines = ["original", "lines"]
|
2016-12-08 07:31:43 -05:00
|
|
|
@ranges = { entries: "mock", comments: "mock" }
|
|
|
|
@updated_ranges = { entries: "updated", comments: "updated" }
|
2017-09-29 07:57:27 -04:00
|
|
|
@appliedOps = [ {v: 42, op: "mock-op-42"}, { v: 45, op: "mock-op-45" }]
|
2017-10-05 08:45:29 -04:00
|
|
|
@doc_ops_length = sinon.stub()
|
|
|
|
@project_ops_length = sinon.stub()
|
2017-09-29 07:57:27 -04:00
|
|
|
@pathname = '/a/b/c.tex'
|
2018-04-23 07:08:04 -04:00
|
|
|
@DocumentManager.getDoc = sinon.stub().yields(null, @lines, @version, @ranges, @pathname, @projectHistoryId)
|
2019-04-11 08:25:03 -04:00
|
|
|
@RangesManager.applyUpdate = sinon.stub().yields(null, @updated_ranges, false)
|
2016-12-01 13:19:47 -05:00
|
|
|
@ShareJsUpdateManager.applyUpdate = sinon.stub().yields(null, @updatedDocLines, @version, @appliedOps)
|
2017-10-05 08:45:29 -04:00
|
|
|
@RedisManager.updateDocument = sinon.stub().yields(null, @doc_ops_length, @project_ops_length)
|
2017-05-02 10:38:33 -04:00
|
|
|
@RealTimeRedisManager.sendData = sinon.stub()
|
2017-09-29 07:57:27 -04:00
|
|
|
@UpdateManager._addProjectHistoryMetadataToOps = sinon.stub()
|
2017-10-05 08:45:29 -04:00
|
|
|
@HistoryManager.recordAndFlushHistoryOps = sinon.stub().callsArg(5)
|
2017-09-29 07:44:36 -04:00
|
|
|
|
2015-06-12 05:14:35 -04:00
|
|
|
describe "normally", ->
|
|
|
|
beforeEach ->
|
2016-09-09 06:01:14 -04:00
|
|
|
@UpdateManager.applyUpdate @project_id, @doc_id, @update, @callback
|
2017-09-29 07:44:36 -04:00
|
|
|
|
2015-06-12 05:14:35 -04:00
|
|
|
it "should apply the updates via ShareJS", ->
|
2016-09-09 06:01:14 -04:00
|
|
|
@ShareJsUpdateManager.applyUpdate
|
2016-12-01 13:19:47 -05:00
|
|
|
.calledWith(@project_id, @doc_id, @update, @lines, @version)
|
|
|
|
.should.equal true
|
2017-09-29 07:44:36 -04:00
|
|
|
|
2016-12-08 07:31:43 -05:00
|
|
|
it "should update the ranges", ->
|
|
|
|
@RangesManager.applyUpdate
|
2017-03-15 10:12:06 -04:00
|
|
|
.calledWith(@project_id, @doc_id, @ranges, @appliedOps, @updatedDocLines)
|
2015-06-12 05:14:35 -04:00
|
|
|
.should.equal true
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2015-06-12 05:14:35 -04:00
|
|
|
it "should save the document", ->
|
2016-08-23 11:00:46 -04:00
|
|
|
@RedisManager.updateDocument
|
2019-04-22 20:02:48 -04:00
|
|
|
.calledWith(@project_id, @doc_id, @updatedDocLines, @version, @appliedOps, @updated_ranges, @updateMeta)
|
2016-08-23 11:00:46 -04:00
|
|
|
.should.equal true
|
2017-09-29 07:44:36 -04:00
|
|
|
|
2017-12-14 09:46:27 -05:00
|
|
|
it "should add metadata to the ops" , ->
|
2017-09-29 07:57:27 -04:00
|
|
|
@UpdateManager._addProjectHistoryMetadataToOps
|
2018-04-23 07:08:04 -04:00
|
|
|
.calledWith(@appliedOps, @pathname, @projectHistoryId, @lines)
|
2017-09-29 07:57:27 -04:00
|
|
|
.should.equal true
|
|
|
|
|
2016-12-08 07:31:43 -05:00
|
|
|
it "should push the applied ops into the history queue", ->
|
2017-05-09 07:02:27 -04:00
|
|
|
@HistoryManager.recordAndFlushHistoryOps
|
2017-10-05 08:45:29 -04:00
|
|
|
.calledWith(@project_id, @doc_id, @appliedOps, @doc_ops_length, @project_ops_length)
|
2015-06-12 05:14:35 -04:00
|
|
|
.should.equal true
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2015-06-12 05:14:35 -04:00
|
|
|
it "should call the callback", ->
|
|
|
|
@callback.called.should.equal true
|
|
|
|
|
|
|
|
describe "with UTF-16 surrogate pairs in the update", ->
|
|
|
|
beforeEach ->
|
2019-06-25 09:01:43 -04:00
|
|
|
@update = {op: [{p: 42, i: "\uD835\uDC00"}], hash: "f1d2d2f924e986ac86fdf7b36c94bcdf32beec15"}
|
2016-09-09 06:01:14 -04:00
|
|
|
@UpdateManager.applyUpdate @project_id, @doc_id, @update, @callback
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2015-06-12 05:14:35 -04:00
|
|
|
it "should apply the update but with surrogate pairs removed", ->
|
2016-09-09 06:01:14 -04:00
|
|
|
@ShareJsUpdateManager.applyUpdate
|
|
|
|
.calledWith(@project_id, @doc_id, @update)
|
2015-06-12 05:14:35 -04:00
|
|
|
.should.equal true
|
2017-09-29 07:44:36 -04:00
|
|
|
|
2015-06-12 05:14:35 -04:00
|
|
|
# \uFFFD is 'replacement character'
|
2016-09-09 06:01:14 -04:00
|
|
|
@update.op[0].i.should.equal "\uFFFD\uFFFD"
|
2017-09-29 07:44:36 -04:00
|
|
|
|
2019-06-25 09:01:43 -04:00
|
|
|
it "should skip the hash check by removing any hash field present", ->
|
|
|
|
@update.should.not.have.property('hash')
|
|
|
|
|
2017-01-10 10:58:11 -05:00
|
|
|
describe "with an error", ->
|
|
|
|
beforeEach ->
|
|
|
|
@error = new Error("something went wrong")
|
|
|
|
@ShareJsUpdateManager.applyUpdate = sinon.stub().yields(@error)
|
|
|
|
@UpdateManager.applyUpdate @project_id, @doc_id, @update, @callback
|
2017-09-29 07:44:36 -04:00
|
|
|
|
2017-05-02 10:38:33 -04:00
|
|
|
it "should call RealTimeRedisManager.sendData with the error", ->
|
|
|
|
@RealTimeRedisManager.sendData
|
2017-01-10 10:58:11 -05:00
|
|
|
.calledWith({
|
|
|
|
project_id: @project_id,
|
|
|
|
doc_id: @doc_id,
|
|
|
|
error: @error.message
|
|
|
|
})
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback with the error", ->
|
|
|
|
@callback.calledWith(@error).should.equal true
|
2017-09-29 07:44:36 -04:00
|
|
|
|
2019-04-11 08:25:03 -04:00
|
|
|
describe "when ranges get collapsed", ->
|
|
|
|
beforeEach ->
|
|
|
|
@RangesManager.applyUpdate = sinon.stub().yields(null, @updated_ranges, true)
|
|
|
|
@SnapshotManager.recordSnapshot = sinon.stub().yields()
|
|
|
|
@UpdateManager.applyUpdate @project_id, @doc_id, @update, @callback
|
|
|
|
|
|
|
|
it "should call SnapshotManager.recordSnapshot", ->
|
|
|
|
@SnapshotManager.recordSnapshot
|
|
|
|
.calledWith(
|
|
|
|
@project_id,
|
|
|
|
@doc_id,
|
|
|
|
@version,
|
2019-04-16 06:05:17 -04:00
|
|
|
@pathname,
|
2019-04-11 08:25:03 -04:00
|
|
|
@lines,
|
|
|
|
@ranges
|
|
|
|
)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
|
2017-09-29 07:57:27 -04:00
|
|
|
describe "_addProjectHistoryMetadataToOps", ->
|
2018-04-23 07:08:04 -04:00
|
|
|
it "should add projectHistoryId, pathname and doc_length metadata to the ops", ->
|
2017-09-29 07:57:27 -04:00
|
|
|
lines = [
|
|
|
|
'some'
|
|
|
|
'test'
|
|
|
|
'data'
|
|
|
|
]
|
2017-12-11 12:26:32 -05:00
|
|
|
appliedOps = [
|
|
|
|
{ v: 42, op: [{i: "foo", p: 4}, { i: "bar", p: 6 }] },
|
|
|
|
{ v: 45, op: [{d: "qux", p: 4}, { i: "bazbaz", p: 14 }] },
|
|
|
|
{ v: 49, op: [{i: "penguin", p: 18}] }
|
|
|
|
]
|
2018-04-23 07:08:04 -04:00
|
|
|
@UpdateManager._addProjectHistoryMetadataToOps(appliedOps, @pathname, @projectHistoryId, lines)
|
2017-09-29 07:57:27 -04:00
|
|
|
appliedOps.should.deep.equal [{
|
2018-04-23 07:08:04 -04:00
|
|
|
projectHistoryId: @projectHistoryId
|
2017-09-29 07:57:27 -04:00
|
|
|
v: 42
|
2017-12-11 12:26:32 -05:00
|
|
|
op: [{i: "foo", p: 4}, { i: "bar", p: 6 }]
|
2017-09-29 07:57:27 -04:00
|
|
|
meta:
|
|
|
|
pathname: @pathname
|
|
|
|
doc_length: 14
|
|
|
|
}, {
|
2018-04-23 07:08:04 -04:00
|
|
|
projectHistoryId: @projectHistoryId
|
2017-09-29 07:57:27 -04:00
|
|
|
v: 45
|
2017-12-11 12:26:32 -05:00
|
|
|
op: [{d: "qux", p: 4}, { i: "bazbaz", p: 14 }]
|
2017-09-29 07:57:27 -04:00
|
|
|
meta:
|
|
|
|
pathname: @pathname
|
2017-12-11 12:26:32 -05:00
|
|
|
doc_length: 20 # 14 + 'foo' + 'bar'
|
|
|
|
}, {
|
2018-04-23 07:08:04 -04:00
|
|
|
projectHistoryId: @projectHistoryId
|
2017-12-11 12:26:32 -05:00
|
|
|
v: 49
|
|
|
|
op: [{i: "penguin", p: 18}]
|
|
|
|
meta:
|
|
|
|
pathname: @pathname
|
|
|
|
doc_length: 23 # 14 - 'qux' + 'bazbaz'
|
2017-09-29 07:57:27 -04:00
|
|
|
}]
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2016-12-01 13:06:33 -05:00
|
|
|
describe "lockUpdatesAndDo", ->
|
|
|
|
beforeEach ->
|
|
|
|
@method = sinon.stub().callsArgWith(3, null, @response_arg1)
|
|
|
|
@callback = sinon.stub()
|
|
|
|
@arg1 = "argument 1"
|
|
|
|
@response_arg1 = "response argument 1"
|
|
|
|
@lockValue = "mock-lock-value"
|
|
|
|
@LockManager.getLock = sinon.stub().callsArgWith(1, null, @lockValue)
|
|
|
|
@LockManager.releaseLock = sinon.stub().callsArg(2)
|
|
|
|
|
|
|
|
describe "successfully", ->
|
|
|
|
beforeEach ->
|
|
|
|
@UpdateManager.continueProcessingUpdatesWithLock = sinon.stub()
|
|
|
|
@UpdateManager.processOutstandingUpdates = sinon.stub().callsArg(2)
|
|
|
|
@UpdateManager.lockUpdatesAndDo @method, @project_id, @doc_id, @arg1, @callback
|
|
|
|
|
|
|
|
it "should lock the doc", ->
|
|
|
|
@LockManager.getLock
|
|
|
|
.calledWith(@doc_id)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should process any outstanding updates", ->
|
|
|
|
@UpdateManager.processOutstandingUpdates
|
|
|
|
.calledWith(@project_id, @doc_id)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the method", ->
|
|
|
|
@method
|
|
|
|
.calledWith(@project_id, @doc_id, @arg1)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should return the method response to the callback", ->
|
|
|
|
@callback
|
|
|
|
.calledWith(null, @response_arg1)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should release the lock", ->
|
|
|
|
@LockManager.releaseLock
|
|
|
|
.calledWith(@doc_id, @lockValue)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should continue processing updates", ->
|
|
|
|
@UpdateManager.continueProcessingUpdatesWithLock
|
|
|
|
.calledWith(@project_id, @doc_id)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
describe "when processOutstandingUpdates returns an error", ->
|
|
|
|
beforeEach ->
|
|
|
|
@UpdateManager.processOutstandingUpdates = sinon.stub().callsArgWith(2, @error = new Error("Something went wrong"))
|
|
|
|
@UpdateManager.lockUpdatesAndDo @method, @project_id, @doc_id, @arg1, @callback
|
|
|
|
|
|
|
|
it "should free the lock", ->
|
|
|
|
@LockManager.releaseLock.calledWith(@doc_id, @lockValue).should.equal true
|
2017-09-29 07:44:36 -04:00
|
|
|
|
2016-12-01 13:06:33 -05:00
|
|
|
it "should return the error in the callback", ->
|
|
|
|
@callback.calledWith(@error).should.equal true
|
|
|
|
|
|
|
|
describe "when the method returns an error", ->
|
|
|
|
beforeEach ->
|
|
|
|
@UpdateManager.processOutstandingUpdates = sinon.stub().callsArg(2)
|
|
|
|
@method = sinon.stub().callsArgWith(3, @error = new Error("something went wrong"), @response_arg1)
|
|
|
|
@UpdateManager.lockUpdatesAndDo @method, @project_id, @doc_id, @arg1, @callback
|
|
|
|
|
|
|
|
it "should free the lock", ->
|
|
|
|
@LockManager.releaseLock.calledWith(@doc_id, @lockValue).should.equal true
|
2017-09-29 07:44:36 -04:00
|
|
|
|
2016-12-01 13:06:33 -05:00
|
|
|
it "should return the error in the callback", ->
|
|
|
|
@callback.calledWith(@error).should.equal true
|
|
|
|
|
|
|
|
|
|
|
|
|