diff --git a/services/document-updater/app/coffee/TrackChangesManager.coffee b/services/document-updater/app/coffee/TrackChangesManager.coffee index 7dfc98115a..9aa1c0ad47 100644 --- a/services/document-updater/app/coffee/TrackChangesManager.coffee +++ b/services/document-updater/app/coffee/TrackChangesManager.coffee @@ -22,7 +22,9 @@ module.exports = TrackChangesManager = return callback(error) FLUSH_EVERY_N_OPS: 50 - pushUncompressedHistoryOps: (project_id, doc_id, ops, callback = (error) ->) -> + pushUncompressedHistoryOps: (project_id, doc_id, ops = [], callback = (error) ->) -> + if ops.length == 0 + return callback() WebRedisManager.pushUncompressedHistoryOps project_id, doc_id, ops, (error, length) -> return callback(error) if error? # We want to flush every 50 ops, i.e. 50, 100, 150, etc diff --git a/services/document-updater/app/coffee/WebRedisManager.coffee b/services/document-updater/app/coffee/WebRedisManager.coffee index 85a056f961..73c099f9da 100644 --- a/services/document-updater/app/coffee/WebRedisManager.coffee +++ b/services/document-updater/app/coffee/WebRedisManager.coffee @@ -24,7 +24,7 @@ module.exports = WebRedisManager = pushUncompressedHistoryOps: (project_id, doc_id, ops = [], callback = (error, length) ->) -> if ops.length == 0 - return callback(null, 0) + return callback(new Error("cannot push no ops")) # This should never be called with no ops, but protect against a redis error if we sent an empty array to rpush jsonOps = ops.map (op) -> JSON.stringify op async.parallel [ (cb) -> rclient.rpush "UncompressedHistoryOps:#{doc_id}", jsonOps..., cb diff --git a/services/document-updater/test/unit/coffee/TrackChangesManager/TrackChangesManagerTests.coffee b/services/document-updater/test/unit/coffee/TrackChangesManager/TrackChangesManagerTests.coffee index 143f01d1ee..03106e2c2e 100644 --- a/services/document-updater/test/unit/coffee/TrackChangesManager/TrackChangesManagerTests.coffee +++ b/services/document-updater/test/unit/coffee/TrackChangesManager/TrackChangesManagerTests.coffee @@ -100,4 +100,13 @@ describe "TrackChangesManager", -> "error flushing doc to track changes api" ) .should.equal true + + describe "with no ops", -> + beforeEach -> + @WebRedisManager.pushUncompressedHistoryOps = sinon.stub().callsArgWith(3, null, 1) + @TrackChangesManager.pushUncompressedHistoryOps @project_id, @doc_id, [], @callback + + it "should not call WebRedisManager.pushUncompressedHistoryOps", -> + @WebRedisManager.pushUncompressedHistoryOps.called.should.equal false + diff --git a/services/document-updater/test/unit/coffee/WebRedisManager/WebRedisManagerTests.coffee b/services/document-updater/test/unit/coffee/WebRedisManager/WebRedisManagerTests.coffee index 107fdaee53..f3f0d8afdc 100644 --- a/services/document-updater/test/unit/coffee/WebRedisManager/WebRedisManagerTests.coffee +++ b/services/document-updater/test/unit/coffee/WebRedisManager/WebRedisManagerTests.coffee @@ -111,5 +111,5 @@ describe "WebRedisManager", -> .called .should.equal false - it "should call the callback with the length", -> - @callback.calledWith(null, 0).should.equal true + it "should call the callback with an error", -> + @callback.calledWith(new Error("cannot push no ops")).should.equal true