From 9d4783e4fc6bb9f4dc5f60d9ecd4b2a31a62155d Mon Sep 17 00:00:00 2001 From: Slava Kim Date: Sun, 23 Feb 2014 17:51:51 -0800 Subject: [PATCH] Additional assert for _safeAppendToBuffer --- packages/mongo-livedata/oplog_observe_driver.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/mongo-livedata/oplog_observe_driver.js b/packages/mongo-livedata/oplog_observe_driver.js index 50f33aa679..65e26bf1c6 100644 --- a/packages/mongo-livedata/oplog_observe_driver.js +++ b/packages/mongo-livedata/oplog_observe_driver.js @@ -174,13 +174,16 @@ _.extend(OplogObserveDriver.prototype, { self._multiplexer.removed(id); if (! self._limit) return; - // xcxc size on heaps should be cached to O(1) if (self._published.size() < self._limit) { // The unpublished buffer is empty iff published contains the whole // matching set, i.e. number of matching documents is less or equal to the // queries limit. - if (! self._unpublishedBuffer.size()) + if (! self._unpublishedBuffer.size()) { + // Assertion of the statement above + if (! self._safeAppendToBuffer && self._phase !== PHASE.QUERYING) + throw new Error("At this phase, buffer can be empty only if published contains the whole matching set"); return; + } var newDocId = self._unpublishedBuffer.minElementId(); var newDoc = self._unpublishedBuffer.get(newDocId);