From 1837e495c5480b7eb2f7019c01e4d5daa31beee4 Mon Sep 17 00:00:00 2001 From: denihs Date: Thu, 16 Feb 2023 06:58:51 -0400 Subject: [PATCH] - fix test: 'mongo-livedata - oplog - include selector fields' --- packages/mongo/mongo_livedata_tests.js | 80 ++++++++++++++------------ 1 file changed, 43 insertions(+), 37 deletions(-) diff --git a/packages/mongo/mongo_livedata_tests.js b/packages/mongo/mongo_livedata_tests.js index 7d7e22fb31..6752127247 100644 --- a/packages/mongo/mongo_livedata_tests.js +++ b/packages/mongo/mongo_livedata_tests.js @@ -3495,47 +3495,53 @@ Meteor.isServer && await observeWithoutOplog.stop(); }); -Meteor.isServer && Tinytest.add("mongo-livedata - oplog - include selector fields", function (test) { - var collName = "includeSelector" + Random.id(); - var coll = new Mongo.Collection(collName); +Meteor.isServer && + Tinytest.addAsync( + 'mongo-livedata - oplog - include selector fields', + async function(test) { + var collName = 'includeSelector' + Random.id(); + var coll = new Mongo.Collection(collName); - var docId = coll.insert({a: 1, b: [3, 2], c: 'foo'}); - test.isTrue(docId); + var docId = await coll.insertAsync({ a: 1, b: [3, 2], c: 'foo' }); + test.isTrue(docId); - // Wait until we've processed the insert oplog entry. (If the insert shows up - // during the observeChanges, the bug in question is not consistently - // reproduced.) We don't have to do this for polling observe (eg - // --disable-oplog). - waitUntilOplogCaughtUp(); + // Wait until we've processed the insert oplog entry. (If the insert shows up + // during the observeChanges, the bug in question is not consistently + // reproduced.) We don't have to do this for polling observe (eg + // --disable-oplog). + await waitUntilOplogCaughtUp(); - var output = []; - var handle = coll.find({a: 1, b: 2}, {fields: {c: 1}}).observeChanges({ - added: function (id, fields) { - output.push(['added', id, fields]); - }, - changed: function (id, fields) { - output.push(['changed', id, fields]); - }, - removed: function (id) { - output.push(['removed', id]); + var output = []; + var handle = await coll + .find({ a: 1, b: 2 }, { fields: { c: 1 } }) + .observeChanges({ + added: function(id, fields) { + output.push(['added', id, fields]); + }, + changed: function(id, fields) { + output.push(['changed', id, fields]); + }, + removed: function(id) { + output.push(['removed', id]); + }, + }); + // Initially should match the document. + test.length(output, 1); + test.equal(output.shift(), ['added', docId, { c: 'foo' }]); + + // Update in such a way that, if we only knew about the published field 'c' + // and the changed field 'b' (but not the field 'a'), we would think it didn't + // match any more. (This is a regression test for a bug that existed because + // we used to not use the shared projection in the initial query.) + await runInFence(async function() { + await coll.updateAsync(docId, { $set: { 'b.0': 2, c: 'bar' } }); + }); + test.length(output, 1); + test.equal(output.shift(), ['changed', docId, { c: 'bar' }]); + + handle.stop(); } - }); - // Initially should match the document. - test.length(output, 1); - test.equal(output.shift(), ['added', docId, {c: 'foo'}]); - - // Update in such a way that, if we only knew about the published field 'c' - // and the changed field 'b' (but not the field 'a'), we would think it didn't - // match any more. (This is a regression test for a bug that existed because - // we used to not use the shared projection in the initial query.) - runInFence(function () { - coll.update(docId, {$set: {'b.0': 2, c: 'bar'}}); - }); - test.length(output, 1); - test.equal(output.shift(), ['changed', docId, {c: 'bar'}]); - - handle.stop(); -}); + ); Meteor.isServer && Tinytest.add("mongo-livedata - oplog - transform", function (test) { var collName = "oplogTransform" + Random.id();