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(); +}; +