|
|
@@ -45,69 +45,48 @@ describe "TrackChangesManager", ->
|
|
|
@op = "mock-op"
|
|
|
@TrackChangesManager.flushDocChanges = sinon.stub().callsArg(2)
|
|
|
|
|
|
- describe "when the doc is under the load manager threshold", ->
|
|
|
+ describe "pushing the op", ->
|
|
|
beforeEach ->
|
|
|
- @RedisManager.getHistoryLoadManagerThreshold = sinon.stub().callsArgWith(0, null, 40)
|
|
|
- @TrackChangesManager.getLoadManagerBucket = sinon.stub().returns(30)
|
|
|
-
|
|
|
- describe "pushing the op", ->
|
|
|
- beforeEach ->
|
|
|
- @RedisManager.pushUncompressedHistoryOp = sinon.stub().callsArgWith(2, null, 1)
|
|
|
- @TrackChangesManager.pushUncompressedHistoryOp @project_id, @doc_id, @op, @callback
|
|
|
-
|
|
|
- it "should push the op into redis", ->
|
|
|
- @RedisManager.pushUncompressedHistoryOp
|
|
|
- .calledWith(@doc_id, @op)
|
|
|
- .should.equal true
|
|
|
-
|
|
|
- it "should call the callback", ->
|
|
|
- @callback.called.should.equal true
|
|
|
-
|
|
|
- it "should not try to flush the op", ->
|
|
|
- @TrackChangesManager.flushDocChanges.called.should.equal false
|
|
|
-
|
|
|
- describe "when there are a multiple of FLUSH_EVERY_N_OPS ops", ->
|
|
|
- beforeEach ->
|
|
|
- @RedisManager.pushUncompressedHistoryOp =
|
|
|
- sinon.stub().callsArgWith(2, null, 2 * @TrackChangesManager.FLUSH_EVERY_N_OPS)
|
|
|
- @TrackChangesManager.pushUncompressedHistoryOp @project_id, @doc_id, @op, @callback
|
|
|
-
|
|
|
- it "should tell the track changes api to flush", ->
|
|
|
- @TrackChangesManager.flushDocChanges
|
|
|
- .calledWith(@project_id, @doc_id)
|
|
|
- .should.equal true
|
|
|
-
|
|
|
- describe "when TrackChangesManager errors", ->
|
|
|
- beforeEach ->
|
|
|
- @RedisManager.pushUncompressedHistoryOp =
|
|
|
- sinon.stub().callsArgWith(2, null, 2 * @TrackChangesManager.FLUSH_EVERY_N_OPS)
|
|
|
- @TrackChangesManager.flushDocChanges = sinon.stub().callsArgWith(2, @error = new Error("oops"))
|
|
|
- @TrackChangesManager.pushUncompressedHistoryOp @project_id, @doc_id, @op, @callback
|
|
|
-
|
|
|
- it "should log out the error", ->
|
|
|
- @logger.error
|
|
|
- .calledWith(
|
|
|
- err: @error
|
|
|
- doc_id: @doc_id
|
|
|
- project_id: @project_id
|
|
|
- "error flushing doc to track changes api"
|
|
|
- )
|
|
|
- .should.equal true
|
|
|
-
|
|
|
- describe "when the doc is over the load manager threshold", ->
|
|
|
- beforeEach ->
|
|
|
- @RedisManager.getHistoryLoadManagerThreshold = sinon.stub().callsArgWith(0, null, 40)
|
|
|
- @TrackChangesManager.getLoadManagerBucket = sinon.stub().returns(50)
|
|
|
- @RedisManager.pushUncompressedHistoryOp = sinon.stub().callsArgWith(2, null, 1)
|
|
|
+ @RedisManager.pushUncompressedHistoryOp = sinon.stub().callsArgWith(3, null, 1)
|
|
|
@TrackChangesManager.pushUncompressedHistoryOp @project_id, @doc_id, @op, @callback
|
|
|
|
|
|
- it "should not push the op", ->
|
|
|
- @RedisManager.pushUncompressedHistoryOp.called.should.equal false
|
|
|
+ it "should push the op into redis", ->
|
|
|
+ @RedisManager.pushUncompressedHistoryOp
|
|
|
+ .calledWith(@project_id, @doc_id, @op)
|
|
|
+ .should.equal true
|
|
|
+
|
|
|
+ it "should call the callback", ->
|
|
|
+ @callback.called.should.equal true
|
|
|
|
|
|
it "should not try to flush the op", ->
|
|
|
@TrackChangesManager.flushDocChanges.called.should.equal false
|
|
|
|
|
|
- it "should call the callback", ->
|
|
|
- @callback.called.should.equal true
|
|
|
+ describe "when there are a multiple of FLUSH_EVERY_N_OPS ops", ->
|
|
|
+ beforeEach ->
|
|
|
+ @RedisManager.pushUncompressedHistoryOp =
|
|
|
+ sinon.stub().callsArgWith(3, null, 2 * @TrackChangesManager.FLUSH_EVERY_N_OPS)
|
|
|
+ @TrackChangesManager.pushUncompressedHistoryOp @project_id, @doc_id, @op, @callback
|
|
|
+
|
|
|
+ it "should tell the track changes api to flush", ->
|
|
|
+ @TrackChangesManager.flushDocChanges
|
|
|
+ .calledWith(@project_id, @doc_id)
|
|
|
+ .should.equal true
|
|
|
+
|
|
|
+ describe "when TrackChangesManager errors", ->
|
|
|
+ beforeEach ->
|
|
|
+ @RedisManager.pushUncompressedHistoryOp =
|
|
|
+ sinon.stub().callsArgWith(3, null, 2 * @TrackChangesManager.FLUSH_EVERY_N_OPS)
|
|
|
+ @TrackChangesManager.flushDocChanges = sinon.stub().callsArgWith(2, @error = new Error("oops"))
|
|
|
+ @TrackChangesManager.pushUncompressedHistoryOp @project_id, @doc_id, @op, @callback
|
|
|
+
|
|
|
+ it "should log out the error", ->
|
|
|
+ @logger.error
|
|
|
+ .calledWith(
|
|
|
+ err: @error
|
|
|
+ doc_id: @doc_id
|
|
|
+ project_id: @project_id
|
|
|
+ "error flushing doc to track changes api"
|
|
|
+ )
|
|
|
+ .should.equal true
|
|
|
|
|
|
|