From dc21bbeb2a47493c3bf442d86efb70c935935dc5 Mon Sep 17 00:00:00 2001 From: denihs Date: Wed, 7 Dec 2022 14:27:34 -0400 Subject: [PATCH 1/4] fixing "livedata - DDP.randomStream" test --- packages/ddp-client/test/random_stream_tests.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/ddp-client/test/random_stream_tests.js b/packages/ddp-client/test/random_stream_tests.js index 03b1ce05ec..b2a44281fe 100644 --- a/packages/ddp-client/test/random_stream_tests.js +++ b/packages/ddp-client/test/random_stream_tests.js @@ -1,8 +1,8 @@ -Tinytest.add('livedata - DDP.randomStream', function(test) { +Tinytest.addAsync('livedata - DDP.randomStream', async function(test) { const randomSeed = Random.id(); const context = { randomSeed: randomSeed }; - let sequence = DDP._CurrentMethodInvocation.withValue(context, function() { + let sequence = await DDP._CurrentMethodInvocation.withValue(context, function() { return DDP.randomStream('1'); }); @@ -21,7 +21,7 @@ Tinytest.add('livedata - DDP.randomStream', function(test) { test.equal(id1, id1Cloned); // We should get the same sequence when we use the same key - sequence = DDP._CurrentMethodInvocation.withValue(context, function() { + sequence = await DDP._CurrentMethodInvocation.withValue(context, function() { return DDP.randomStream('1'); }); seeds = sequence.alea.args; From aae8843a25db7bc6700e1a9dacf6a4efa605482d Mon Sep 17 00:00:00 2001 From: denihs Date: Thu, 8 Dec 2022 10:42:27 -0400 Subject: [PATCH 2/4] fixing "livedata - changing userid reruns subscriptions without flapping data on the wire" test --- .../ddp-client/test/livedata_test_service.js | 73 ++++++------- packages/ddp-client/test/livedata_tests.js | 100 ++++++++++-------- 2 files changed, 95 insertions(+), 78 deletions(-) diff --git a/packages/ddp-client/test/livedata_test_service.js b/packages/ddp-client/test/livedata_test_service.js index 9a3aa7cc6f..d278a8932b 100644 --- a/packages/ddp-client/test/livedata_test_service.js +++ b/packages/ddp-client/test/livedata_test_service.js @@ -157,47 +157,48 @@ Meteor.methods({ objectsWithUsers = new Mongo.Collection('objectsWithUsers'); -if (Meteor.isServer) { - objectsWithUsers.remove({}); - objectsWithUsers.insert({ name: 'owned by none', ownerUserIds: [null] }); - objectsWithUsers.insert({ name: 'owned by one - a', ownerUserIds: ['1'] }); - objectsWithUsers.insert({ - name: 'owned by one/two - a', - ownerUserIds: ['1', '2'] - }); - objectsWithUsers.insert({ - name: 'owned by one/two - b', - ownerUserIds: ['1', '2'] - }); - objectsWithUsers.insert({ name: 'owned by two - a', ownerUserIds: ['2'] }); - objectsWithUsers.insert({ name: 'owned by two - b', ownerUserIds: ['2'] }); +Meteor.startup(async function() { + if (Meteor.isServer) { + await objectsWithUsers.removeAsync({}); + await objectsWithUsers.insertAsync({name: 'owned by none', ownerUserIds: [null]}); + await objectsWithUsers.insertAsync({name: 'owned by one - a', ownerUserIds: ['1']}); + await objectsWithUsers.insertAsync({ + name: 'owned by one/two - a', + ownerUserIds: ['1', '2'] + }); + await objectsWithUsers.insertAsync({ + name: 'owned by one/two - b', + ownerUserIds: ['1', '2'] + }); + await objectsWithUsers.insertAsync({name: 'owned by two - a', ownerUserIds: ['2']}); + await objectsWithUsers.insertAsync({name: 'owned by two - b', ownerUserIds: ['2']}); - Meteor.publish('objectsWithUsers', function() { - return objectsWithUsers.find( - { ownerUserIds: this.userId }, - { fields: { ownerUserIds: 0 } } - ); - }); - - (function() { - const userIdWhenStopped = Object.create(null); - Meteor.publish('recordUserIdOnStop', function(key) { - check(key, String); - const self = this; - self.onStop(function() { - userIdWhenStopped[key] = self.userId; - }); + Meteor.publish('objectsWithUsers', function () { + return objectsWithUsers.find( + {ownerUserIds: this.userId}, + {fields: {ownerUserIds: 0}} + ); }); - Meteor.methods({ - userIdWhenStopped: function(key) { + (function () { + const userIdWhenStopped = Object.create(null); + Meteor.publish('recordUserIdOnStop', function (key) { check(key, String); - return userIdWhenStopped[key]; - } - }); - })(); -} + const self = this; + self.onStop(function () { + userIdWhenStopped[key] = self.userId; + }); + }); + Meteor.methods({ + userIdWhenStopped: function (key) { + check(key, String); + return userIdWhenStopped[key]; + } + }); + })(); + } +}); /*****/ /// Helper for "livedata - setUserId fails when called on server" diff --git a/packages/ddp-client/test/livedata_tests.js b/packages/ddp-client/test/livedata_tests.js index 66a835ae8f..2005952141 100644 --- a/packages/ddp-client/test/livedata_tests.js +++ b/packages/ddp-client/test/livedata_tests.js @@ -1,6 +1,8 @@ import { DDP } from '../common/namespace.js'; import { Connection } from '../common/livedata_connection.js'; +const _sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); + // XXX should check error codes const failure = function(test, code, reason) { return function(error, result) { @@ -435,7 +437,7 @@ if (Meteor.isClient) { testAsyncMulti( 'livedata - changing userid reruns subscriptions without flapping data on the wire', [ - function(test, expect) { + async function(test, expect) { const messages = []; const undoEavesdrop = eavesdropOnCollection( Meteor.connection, @@ -484,54 +486,68 @@ if (Meteor.isClient) { let afterSecondSetUserId; let afterThirdSetUserId; - Meteor.subscribe( - 'objectsWithUsers', - expect(function() { - expectMessages(1, 0, ['owned by none']); - Meteor.apply( - 'setUserId', - ['1'], - { wait: true }, - afterFirstSetUserId - ); - }) - ); + const handle = Meteor.subscribe('objectsWithUsers'); - afterFirstSetUserId = expect(function() { - expectMessages(3, 1, [ - 'owned by one - a', - 'owned by one/two - a', - 'owned by one/two - b' - ]); + let control = 0; + // Just make sure the subscription is ready before running the tests + // As everything now runs async, the tests were running before the data fully came in + while (!handle.ready()) { + if (!handle.ready()) { + // Just in case something happens with the subscription, we have this control + if (control++ === 1000) { + throw new Error("Subscribe to objectsWithUsers is taking too long!"); + } + await _sleep(0); + return; + } + expectMessages(1, 0, ['owned by none']); Meteor.apply( 'setUserId', - ['2'], + ['1'], { wait: true }, - afterSecondSetUserId + afterFirstSetUserId ); - }); + afterFirstSetUserId = expect(function() { + expectMessages(3, 1, [ + 'owned by one - a', + 'owned by one/two - a', + 'owned by one/two - b', + ]); + Meteor.apply( + 'setUserId', + ['2'], + { wait: true }, + afterSecondSetUserId + ); + }); - afterSecondSetUserId = expect(function() { - expectMessages(2, 1, [ - 'owned by one/two - a', - 'owned by one/two - b', - 'owned by two - a', - 'owned by two - b' - ]); - Meteor.apply('setUserId', ['2'], { wait: true }, afterThirdSetUserId); - }); + afterSecondSetUserId = expect(function() { + expectMessages(2, 1, [ + 'owned by one/two - a', + 'owned by one/two - b', + 'owned by two - a', + 'owned by two - b', + ]); + Meteor.apply( + 'setUserId', + ['2'], + { wait: true }, + afterThirdSetUserId + ); + }); - afterThirdSetUserId = expect(function() { - // Nothing should have been sent since the results of the - // query are the same ("don't flap data on the wire") - expectMessages(0, 0, [ - 'owned by one/two - a', - 'owned by one/two - b', - 'owned by two - a', - 'owned by two - b' - ]); - undoEavesdrop(); - }); + afterThirdSetUserId = expect(function() { + // Nothing should have been sent since the results of the + // query are the same ("don't flap data on the wire") + expectMessages(0, 0, [ + 'owned by one/two - a', + 'owned by one/two - b', + 'owned by two - a', + 'owned by two - b', + ]); + undoEavesdrop(); + }); + } }, function(test, expect) { const key = Random.id(); From aee880e2bc6c1df871b2cd915b462df24c1466b3 Mon Sep 17 00:00:00 2001 From: denihs Date: Thu, 8 Dec 2022 12:47:55 -0400 Subject: [PATCH 3/4] fixing "livedata - compound methods" test --- .../ddp-client/test/livedata_test_service.js | 14 +- packages/ddp-client/test/livedata_tests.js | 249 ++++++++++-------- 2 files changed, 150 insertions(+), 113 deletions(-) diff --git a/packages/ddp-client/test/livedata_test_service.js b/packages/ddp-client/test/livedata_test_service.js index d278a8932b..8938a1a8ca 100644 --- a/packages/ddp-client/test/livedata_test_service.js +++ b/packages/ddp-client/test/livedata_test_service.js @@ -109,8 +109,8 @@ Ledger.allow({ fetch: [] }); -Meteor.startup(function() { - if (Meteor.isServer) Ledger.remove({}); // XXX can this please be Ledger.remove()? +Meteor.startup(async function() { + if (Meteor.isServer) await Ledger.removeAsync({}); }); if (Meteor.isServer) @@ -120,14 +120,14 @@ if (Meteor.isServer) }); Meteor.methods({ - 'ledger/transfer': function(world, from_name, to_name, amount, cheat) { + 'ledger/transfer': async function(world, from_name, to_name, amount, cheat) { check(world, String); check(from_name, String); check(to_name, String); check(amount, Number); check(cheat, Match.Optional(Boolean)); - const from = Ledger.findOne({ name: from_name, world: world }); - const to = Ledger.findOne({ name: to_name, world: world }); + const from = await Ledger.findOneAsync({ name: from_name, world: world }); + const to = await Ledger.findOneAsync({ name: to_name, world: world }); if (Meteor.isServer) cheat = false; @@ -146,8 +146,8 @@ Meteor.methods({ if (from.balance < amount && !cheat) throw new Meteor.Error(409, 'Insufficient funds'); - Ledger.update(from._id, { $inc: { balance: -amount } }); - Ledger.update(to._id, { $inc: { balance: amount } }); + await Ledger.updateAsync({_id: from._id}, { $inc: { balance: -amount } }); + await Ledger.updateAsync({_id: to._id, }, { $inc: { balance: amount } }); } }); diff --git a/packages/ddp-client/test/livedata_tests.js b/packages/ddp-client/test/livedata_tests.js index 2005952141..3c181410eb 100644 --- a/packages/ddp-client/test/livedata_tests.js +++ b/packages/ddp-client/test/livedata_tests.js @@ -1,7 +1,23 @@ import { DDP } from '../common/namespace.js'; import { Connection } from '../common/livedata_connection.js'; -const _sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); +const _sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); + +const callWhenSubReady = async (subName, handle, cb = () => {}) => { + let control = 0; + + while (!handle.ready()) { + if (!handle.ready()) { + // Just in case something happens with the subscription, we have this control + if (control++ === 1000) { + throw new Error(`Subscribe to ${subName} is taking too long!`); + } + await _sleep(0); + return; + } + await cb(); + } +}; // XXX should check error codes const failure = function(test, code, reason) { @@ -131,7 +147,8 @@ testAsyncMulti('livedata - basic method invocation', [ // make sure 'undefined' is preserved as such, instead of turning // into null (JSON does not have 'undefined' so there is special // code for this) - if (Meteor.isServer) test.equal(await Meteor.callAsync('nothing'), undefined); + if (Meteor.isServer) + test.equal(await Meteor.callAsync('nothing'), undefined); if (Meteor.isClient) test.equal(Meteor.call('nothing'), undefined); test.equal(Meteor.call('nothing', expect(undefined, undefined)), undefined); @@ -157,7 +174,10 @@ testAsyncMulti('livedata - basic method invocation', [ async function(test, expect) { if (Meteor.isServer) - test.equal(await Meteor.callAsync('echo', 12, { x: 13 }), [12, { x: 13 }]); + test.equal(await Meteor.callAsync('echo', 12, { x: 13 }), [ + 12, + { x: 13 }, + ]); if (Meteor.isClient) test.equal(Meteor.call('echo', 12, { x: 13 }), undefined); @@ -294,7 +314,7 @@ testAsyncMulti('livedata - basic method invocation', [ try { await Meteor.callAsync('exception', 'both', { intended: true, - throwThroughFuture: true + throwThroughFuture: true, }); } catch (e) { threw = true; @@ -329,74 +349,81 @@ testAsyncMulti('livedata - basic method invocation', [ 'server', { intended: true, - throwThroughFuture: true + throwThroughFuture: true, }, expect(failure(test, 999, 'Client-visible test exception')) ), undefined ); } - } + }, ]); -const checkBalances = function(test, a, b) { - const alice = Ledger.findOne({ name: 'alice', world: test.runId() }); - const bob = Ledger.findOne({ name: 'bob', world: test.runId() }); +const checkBalances = async function(test, a, b) { + const alice = await Ledger.findOneAsync({ + name: 'alice', + world: test.runId(), + }); + const bob = await Ledger.findOneAsync({ name: 'bob', world: test.runId() }); + test.equal(alice.balance, a); test.equal(bob.balance, b); }; +const subscribeBeforeRun = async (subName, testId, cb) => { + if (Meteor.isClient) { + const handle = Meteor.subscribe(subName, testId); + await callWhenSubReady(subName, handle); + handle.stop(); + } + await cb(); +}; + // would be nice to have a database-aware test harness of some kind -- // this is a big hack (and XXX pollutes the global test namespace) testAsyncMulti('livedata - compound methods', [ - function(test, expect) { - if (Meteor.isClient) Meteor.subscribe('ledger', test.runId(), expect()); - - Ledger.insert( - { name: 'alice', balance: 100, world: test.runId() }, - expect(function() {}) - ); - Ledger.insert( - { name: 'bob', balance: 50, world: test.runId() }, - expect(function() {}) - ); + async function(test) { + await Ledger.insertAsync({ + name: 'alice', + balance: 100, + world: test.runId(), + }); + await Ledger.insertAsync({ name: 'bob', balance: 50, world: test.runId() }); }, - function(test, expect) { - Meteor.call( - 'ledger/transfer', - test.runId(), - 'alice', - 'bob', - 10, - expect(function(err, result) { - test.equal(err, undefined); - test.equal(result, undefined); - checkBalances(test, 90, 60); - }) - ); - checkBalances(test, 90, 60); + async function(test) { + await subscribeBeforeRun('ledger', test.runId(), async () => { + await Meteor.callAsync( + 'ledger/transfer', + test.runId(), + 'alice', + 'bob', + 10 + ); + await checkBalances(test, 90, 60); + }); }, - function(test, expect) { - Meteor.call( - 'ledger/transfer', - test.runId(), - 'alice', - 'bob', - 100, - true, - expect(function(err, result) { - failure(test, 409)(err, result); - // Balances are reverted back to pre-stub values. - checkBalances(test, 90, 60); - }) - ); + async function(test) { + await subscribeBeforeRun('ledger', test.runId(), async () => { + try { + await Meteor.callAsync( + 'ledger/transfer', + test.runId(), + 'alice', + 'bob', + 100, + true + ); + } catch (e) {} - if (Meteor.isClient) - // client can fool itself by cheating, but only until the sync - // finishes - checkBalances(test, -10, 160); - else checkBalances(test, 90, 60); - } + if (Meteor.isClient) { + // client can fool itself by cheating, but only until the sync + // finishes + await checkBalances(test, -10, 160); + } else { + await checkBalances(test, 90, 60); + } + }); + }, ]); // Replaces the Connection's `_livedata_data` method to push incoming @@ -488,25 +515,11 @@ if (Meteor.isClient) { const handle = Meteor.subscribe('objectsWithUsers'); - let control = 0; // Just make sure the subscription is ready before running the tests // As everything now runs async, the tests were running before the data fully came in - while (!handle.ready()) { - if (!handle.ready()) { - // Just in case something happens with the subscription, we have this control - if (control++ === 1000) { - throw new Error("Subscribe to objectsWithUsers is taking too long!"); - } - await _sleep(0); - return; - } + await callWhenSubReady('objectsWithUsers', handle, () => { expectMessages(1, 0, ['owned by none']); - Meteor.apply( - 'setUserId', - ['1'], - { wait: true }, - afterFirstSetUserId - ); + Meteor.apply('setUserId', ['1'], { wait: true }, afterFirstSetUserId); afterFirstSetUserId = expect(function() { expectMessages(3, 1, [ 'owned by one - a', @@ -547,7 +560,7 @@ if (Meteor.isClient) { ]); undoEavesdrop(); }); - } + }); }, function(test, expect) { const key = Random.id(); @@ -579,7 +592,7 @@ if (Meteor.isClient) { { wait: true }, expect(function() {}) ); - } + }, ] ); } @@ -630,7 +643,7 @@ Meteor.methods({ return 2; } return 0; - } + }, }); if (Meteor.isClient) { @@ -639,12 +652,22 @@ if (Meteor.isClient) { const id = Random.id(); testAsyncMulti('livedata - added from two different subs', [ function(test, expect) { - Meteor.call('livedata/setup', id, expect(function() {})); + Meteor.call( + 'livedata/setup', + id, + expect(function() {}) + ); }, function(test, expect) { MultiPub = new Mongo.Collection('MultiPubCollection' + id); - const sub1 = Meteor.subscribe('pub1' + id, expect(function() {})); - const sub2 = Meteor.subscribe('pub2' + id, expect(function() {})); + const sub1 = Meteor.subscribe( + 'pub1' + id, + expect(function() {}) + ); + const sub2 = Meteor.subscribe( + 'pub2' + id, + expect(function() {}) + ); }, function(test, expect) { Meteor.call( @@ -669,7 +692,7 @@ if (Meteor.isClient) { }, function(test, expect) { test.equal(MultiPub.findOne('foo'), { _id: 'foo', a: 'aa', b: 'bb' }); - } + }, ]); })(); } @@ -688,7 +711,7 @@ if (Meteor.isClient) { test.isTrue(coll.findOne(token)); }) ); - } + }, ]); testAsyncMulti('livedata - runtime universal sub creation', [ @@ -704,7 +727,7 @@ if (Meteor.isClient) { test.isTrue(coll.findOne(token)); }) ); - } + }, ]); testAsyncMulti('livedata - no setUserId after unblock', [ @@ -716,7 +739,7 @@ if (Meteor.isClient) { test.isTrue(result); }) ); - } + }, ]); testAsyncMulti( @@ -730,7 +753,7 @@ if (Meteor.isClient) { // Use a separate connection so that we can safely check to see if // conn._subscriptions is empty. conn = new Connection('/', { - reloadWithOutstanding: true + reloadWithOutstanding: true, }); collName = Random.id(); coll = new Mongo.Collection(collName, { connection: conn }); @@ -746,7 +769,7 @@ if (Meteor.isClient) { ? 'Internal server error' : 'Explicit error' ) - ) + ), }); }; testSubError({ throwInHandler: true }); @@ -768,7 +791,7 @@ if (Meteor.isClient) { onReady: expect(), onError: function(error) { errorFromRerun = error; - } + }, } ); }, @@ -777,7 +800,11 @@ if (Meteor.isClient) { test.equal(coll.find().count(), 1); test.isFalse(errorFromRerun); test.equal(_.size(conn._subscriptions), 1); // white-box test - conn.call('setUserId', 'bla', expect(function() {})); + conn.call( + 'setUserId', + 'bla', + expect(function() {}) + ); }, function(test, expect) { // Now that we've re-run, we should have stopped the subscription, @@ -796,13 +823,16 @@ if (Meteor.isClient) { { onError: function() { gotErrorFromStopper = true; - } + }, } ); // Call a method. This method won't be processed until the publisher's // function returns, so blocking on it being done ensures that we've // gotten the removed/nosub/etc. - conn.call('nothing', expect(function() {})); + conn.call( + 'nothing', + expect(function() {}) + ); }, function(test, expect) { test.equal(coll.find().count(), 0); @@ -810,7 +840,7 @@ if (Meteor.isClient) { test.isFalse(gotErrorFromStopper); test.equal(_.size(conn._subscriptions), 0); // white-box test conn._stream.disconnect({ _permanent: true }); - } + }, ]; })() ); @@ -826,7 +856,7 @@ if (Meteor.isClient) { // Use a separate connection so that we can safely check to see if // conn._subscriptions is empty. conn = new Connection('/', { - reloadWithOutstanding: true + reloadWithOutstanding: true, }); collName = Random.id(); coll = new Mongo.Collection(collName, { connection: conn }); @@ -842,7 +872,7 @@ if (Meteor.isClient) { ? 'Internal server error' : 'Explicit error' ) - ) + ), }); }; testSubError({ throwInHandler: true }); @@ -864,7 +894,7 @@ if (Meteor.isClient) { onReady: expect(), onStop: function(error) { errorFromRerun = error; - } + }, } ); }, @@ -873,7 +903,11 @@ if (Meteor.isClient) { test.equal(coll.find().count(), 1); test.isFalse(errorFromRerun); test.equal(_.size(conn._subscriptions), 1); // white-box test - conn.call('setUserId', 'bla', expect(function() {})); + conn.call( + 'setUserId', + 'bla', + expect(function() {}) + ); }, function(test, expect) { // Now that we've re-run, we should have stopped the subscription, @@ -894,13 +928,16 @@ if (Meteor.isClient) { if (error) { gotErrorFromStopper = true; } - } + }, } ); // Call a method. This method won't be processed until the publisher's // function returns, so blocking on it being done ensures that we've // gotten the removed/nosub/etc. - conn.call('nothing', expect(function() {})); + conn.call( + 'nothing', + expect(function() {}) + ); }, function(test, expect) { test.equal(coll.find().count(), 0); @@ -908,7 +945,7 @@ if (Meteor.isClient) { test.isFalse(gotErrorFromStopper); test.equal(_.size(conn._subscriptions), 0); // white-box test conn._stream.disconnect({ _permanent: true }); - } + }, ]; })() ); @@ -924,7 +961,7 @@ if (Meteor.isClient) { test.equal(One.find().count(), 2); test.equal(Two.find().count(), 3); }), - onError: failure() + onError: failure(), } ); }, @@ -934,7 +971,7 @@ if (Meteor.isClient) { { dup: 1 }, { onReady: failure(), - onError: expect(failure(test, 500, 'Internal server error')) + onError: expect(failure(test, 500, 'Internal server error')), } ); }, @@ -944,10 +981,10 @@ if (Meteor.isClient) { { notCursor: 1 }, { onReady: failure(), - onError: expect(failure(test, 500, 'Internal server error')) + onError: expect(failure(test, 500, 'Internal server error')), } ); - } + }, ]); } @@ -960,7 +997,7 @@ if (Meteor.isServer) { s2s: function(arg) { check(arg, String); return 's2s ' + arg; - } + }, }); } (function() { @@ -989,7 +1026,7 @@ if (Meteor.isServer) { }) ); } - } + }, ]); })(); @@ -1013,7 +1050,7 @@ if (Meteor.isServer) { if (self.conn.status().connected) { test.equal(await self.conn.callAsync('s2s', 'foo'), 's2s foo'); } - } + }, ]); })(); } @@ -1030,7 +1067,7 @@ if (Meteor.isServer) { }), 500 ); - } + }, ]); })(); @@ -1054,13 +1091,13 @@ if (Meteor.isServer) { onReady: expect(function() { test.equal(PublisherCloningCollection.findOne(), { _id: 'a', - x: { y: 43 } + x: { y: 43 }, }); }), - onError: failure() + onError: failure(), } ); - } + }, ]); } @@ -1099,7 +1136,7 @@ testAsyncMulti('livedata - result by value', [ test.equal(self.firstResult.length + 1, secondResult.length); }) ); - } + }, ]); // XXX some things to test in greater detail: From fa878234ad306b93a79af10b27962bcda5d2faed Mon Sep 17 00:00:00 2001 From: denihs Date: Thu, 8 Dec 2022 13:02:53 -0400 Subject: [PATCH 4/4] fixing "publish multiple cursors" test --- .../ddp-client/test/livedata_test_service.js | 58 ++++++++++--------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/packages/ddp-client/test/livedata_test_service.js b/packages/ddp-client/test/livedata_test_service.js index 8938a1a8ca..57c47b1e8d 100644 --- a/packages/ddp-client/test/livedata_test_service.js +++ b/packages/ddp-client/test/livedata_test_service.js @@ -333,36 +333,38 @@ if (Meteor.isServer) { One = new Mongo.Collection('collectionOne'); Two = new Mongo.Collection('collectionTwo'); -if (Meteor.isServer) { - One.remove({}); - One.insert({ name: 'value1' }); - One.insert({ name: 'value2' }); +Meteor.startup(async () => { + if (Meteor.isServer) { + await One.removeAsync({}); + await One.insertAsync({ name: 'value1' }); + await One.insertAsync({ name: 'value2' }); - Two.remove({}); - Two.insert({ name: 'value3' }); - Two.insert({ name: 'value4' }); - Two.insert({ name: 'value5' }); + await Two.removeAsync({}); + await Two.insertAsync({ name: 'value3' }); + await Two.insertAsync({ name: 'value4' }); + await Two.insertAsync({ name: 'value5' }); - Meteor.publish('multiPublish', function(options) { - // See below to see what options are accepted. - check(options, Object); - if (options.normal) { - return [One.find(), Two.find()]; - } else if (options.dup) { - // Suppress the log of the expected internal error. - Meteor._suppress_log(1); - return [ - One.find(), - One.find({ name: 'value2' }), // multiple cursors for one collection - error - Two.find() - ]; - } else if (options.notCursor) { - // Suppress the log of the expected internal error. - Meteor._suppress_log(1); - return [One.find(), 'not a cursor', Two.find()]; - } else throw 'unexpected options'; - }); -} + Meteor.publish('multiPublish', function(options) { + // See below to see what options are accepted. + check(options, Object); + if (options.normal) { + return [One.find(), Two.find()]; + } else if (options.dup) { + // Suppress the log of the expected internal error. + Meteor._suppress_log(1); + return [ + One.find(), + One.find({ name: 'value2' }), // multiple cursors for one collection - error + Two.find(), + ]; + } else if (options.notCursor) { + // Suppress the log of the expected internal error. + Meteor._suppress_log(1); + return [One.find(), 'not a cursor', Two.find()]; + } else throw 'unexpected options'; + }); + } +}); /// Helper for "livedata - result by value" const resultByValueArrays = Object.create(null);