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

EAGLESIX-812 fixed batch loop and test cases

Phil Murray 11 лет назад
Родитель
Сommit
6c976dcedc

+ 9 - 6
lib/pipeline/documentSources/CursorDocumentSource.js

@@ -191,10 +191,11 @@ proto.loadBatch = function loadBatch(callback) {
 	this._runner.restoreState();
 
 	var self = this,
-		continueWhile = true;
+		whileBreak = false,
+		whileReturn = false;
 	return async.whilst(
 		function test(){
-			return continueWhile === true;
+			return !whileBreak && !whileReturn;
 		},
 		function(next) {
 			return self._runner.getNext(function(err, obj, state){
@@ -208,7 +209,7 @@ proto.loadBatch = function loadBatch(callback) {
 
 					if (self._limit) {
 						if (++self._docsAddedToBatches === self._limit.getLimit()) {
-							continueWhile = false;
+							whileBreak = true;
 							return next();
 						}
 						//this was originally a 'verify' in the mongo code
@@ -220,16 +221,18 @@ proto.loadBatch = function loadBatch(callback) {
 					if (self._currentBatch >= klass.MaxDocumentsToReturnToClientAtOnce) {
 						// End self batch and prepare Runner for yielding.
 						self._runner.saveState();
-						continueWhile = false;
+						whileReturn = true;
 					}
 				} else {
-					continueWhile = false;
+					whileBreak = true;
 				}
 				return next();
 			});
 		},
 		function(err){
-			self._runner.reset();
+			if (!whileReturn){
+				self._runner.reset();
+			}
 			callback(err);
 		}
 	);

+ 0 - 27
test/lib/pipeline/documentSources/CursorDocumentSource.js

@@ -141,33 +141,6 @@ module.exports = {
 				cds.setProjection({a:1}, {a:true});
 				assert.deepEqual(cds._projection, {a:1});
 				assert.deepEqual(cds._dependencies, {a:true});
-			},
-
-			"should throw an error if projection is already set": function (){
-				var cds = getCursorDocumentSource();
-				cds.setProjection({a:1}, {});
-				assert.throws(function() {
-					cds.setProjection({a:1}, {});
-				});
-			},
-
-			"should project properly": function(next) {
-				var cds = getCursorDocumentSource([{a:1},{a:2,b:3},{c:4,d:5}]);
-				cds.setProjection({a:1}, {a:true});
-				assert.deepEqual(cds._projection, {a:1});
-				assert.deepEqual(cds._dependencies, {a:true});
-
-				async.series([
-						cds.getNext.bind(cds),
-						cds.getNext.bind(cds),
-						cds.getNext.bind(cds),
-						cds.getNext.bind(cds),
-					],
-					function(err,res) {
-						assert.deepEqual([{a:1},{a:2},{},null], res);
-						next();
-					}
-				);
 			}
 
 		}