From 0aa9af3dfc6460291bbb37f5f39408cacd09be61 Mon Sep 17 00:00:00 2001 From: David Glasser Date: Mon, 17 Mar 2014 11:10:06 -0700 Subject: [PATCH] Make some white-box tests less flaky If we want the *internal* state of the oplog driver to be consistent, we need to make sure that we start our observes at a consistent point in the oplog. (ie, initial inserts need to have been fully processed, so that we don't process them during the original QUERYING phase, which can give us a different unpublished buffer.) Note that only the white-box tests (looked at _unpublishedBuffer, eg) appeared to be flaky: the actual docs published seemed to be correct in all cases. --- .../mongo-livedata/mongo_livedata_tests.js | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/mongo-livedata/mongo_livedata_tests.js b/packages/mongo-livedata/mongo_livedata_tests.js index 48dfa6fa92..20f2126886 100644 --- a/packages/mongo-livedata/mongo_livedata_tests.js +++ b/packages/mongo-livedata/mongo_livedata_tests.js @@ -818,6 +818,8 @@ if (Meteor.isServer) { // Insert a doc and start observing. var docId1 = ins({foo: 22, bar: 5}); + waitUntilOplogCaughtUp(); + // State: [ 5:1 | ]! var o = observer(); var usesOplog = o.handle._multiplexer._observeDriver._usesOplog; @@ -1154,6 +1156,10 @@ if (Meteor.isServer) { ids[i] = ins({ x: x, y: i }); }); + // Ensure that we are past all the 'i' entries before we run the query, so + // that we get the expected phase transitions. + waitUntilOplogCaughtUp(); + var o = observer(); var usesOplog = o.handle._multiplexer._observeDriver._usesOplog; // x: [1 1 2 | 2 3 3] 4 5 5 5 9 @@ -2407,8 +2413,7 @@ Meteor.isServer && Tinytest.add("mongo-livedata - oplog - include selector field // during the observeChanges, the bug in question is not consistently // reproduced.) We don't have to do this for polling observe (eg // --disable-oplog). - var oplog = MongoInternals.defaultRemoteCollectionDriver().mongo._oplogHandle; - oplog && oplog.waitUntilCaughtUp(); + waitUntilOplogCaughtUp(); var output = []; var handle = coll.find({a: 1, b: 2}, {fields: {c: 1}}).observeChanges({ @@ -2450,8 +2455,7 @@ Meteor.isServer && Tinytest.add("mongo-livedata - oplog - transform", function ( // during the observeChanges, the bug in question is not consistently // reproduced.) We don't have to do this for polling observe (eg // --disable-oplog). - var oplog = MongoInternals.defaultRemoteCollectionDriver().mongo._oplogHandle; - oplog && oplog.waitUntilCaughtUp(); + waitUntilOplogCaughtUp(); var cursor = coll.find({}, {transform: function (doc) { return doc.x; @@ -2513,8 +2517,7 @@ Meteor.isServer && Tinytest.add("mongo-livedata - oplog - drop collection", func // Wait until we've processed the insert oplog entry, so that we are in a // steady state (and we don't see the dropped docs because we are FETCHING). - var oplog = MongoInternals.defaultRemoteCollectionDriver().mongo._oplogHandle; - oplog && oplog.waitUntilCaughtUp(); + waitUntilOplogCaughtUp(); // Drop the collection. Should remove all docs. runInFence(function () { @@ -2664,3 +2667,12 @@ testAsyncMulti("mongo-livedata - oplog - update EJSON", [ self.handle.stop(); } ]); + + +var waitUntilOplogCaughtUp = function () { + var oplogHandle = + MongoInternals.defaultRemoteCollectionDriver().mongo._oplogHandle; + if (oplogHandle) + oplogHandle.waitUntilCaughtUp(); +}; +