Просмотр исходного кода

Move check of zero length op array up a level

James Allen 10 лет назад
Родитель
Сommit
5ce15c4d60

+ 3 - 1
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

+ 1 - 1
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

+ 9 - 0
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
+			
 

+ 2 - 2
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