From d9d9a4b1712d058cfdd997c4b03c5e77f75d1294 Mon Sep 17 00:00:00 2001 From: Jesse Rosenberger Date: Thu, 21 Apr 2016 19:12:20 +0300 Subject: [PATCH 1/3] Tests need to be async since the livedata updates might not happen in the same tick anymore. --- tests/client/ddp_update.js | 31 +++++++++++++++--------- tests/client/fast_render.js | 47 ++++++++++++++++++++++--------------- tests/utils.js | 2 ++ 3 files changed, 50 insertions(+), 30 deletions(-) diff --git a/tests/client/ddp_update.js b/tests/client/ddp_update.js index 31a0781..90a920d 100644 --- a/tests/client/ddp_update.js +++ b/tests/client/ddp_update.js @@ -1,4 +1,4 @@ -Tinytest.add('DDPUpdate - convert added to changed', function(test) { +Tinytest.addAsync('DDPUpdate - convert added to changed', function(test, done) { var collName = Random.id(); var coll = new Mongo.Collection(collName); @@ -9,19 +9,25 @@ Tinytest.add('DDPUpdate - convert added to changed', function(test) { fields: {name: "arunoda"} }); - test.equal(coll.findOne('one'), {_id: 'one', name: 'arunoda'}); + Meteor.setTimeout(function () { + test.equal(coll.findOne('one'), {_id: 'one', name: 'arunoda'}); - Meteor.connection._livedata_data({ - msg: 'added', - collection: collName, - id: 'one', - fields: {name: "kuma", age: 20} - }); + Meteor.connection._livedata_data({ + msg: 'added', + collection: collName, + id: 'one', + fields: {name: "kuma", age: 20} + }); + + Meteor.setTimeout(function () { + test.equal(coll.findOne('one'), {_id: 'one', name: 'kuma', age: 20}); + done(); + }, bufferedWritesInterval); - test.equal(coll.findOne('one'), {_id: 'one', name: 'kuma', age: 20}); + }, bufferedWritesInterval); }); -Tinytest.add('DDPUpdate - create collection later on', function(test) { +Tinytest.addAsync('DDPUpdate - create collection later on', function(test, done) { var collName = Random.id(); Meteor.connection._livedata_data({ @@ -39,7 +45,10 @@ Tinytest.add('DDPUpdate - create collection later on', function(test) { }); var coll = new Mongo.Collection(collName); - test.equal(coll.find().fetch().length, 2); + Meteor.setTimeout(function () { + test.equal(coll.find().fetch().length, 2); + done(); + }, bufferedWritesInterval); }); Tinytest.add('DDPUpdate - delete subscriptions', function(test) { diff --git a/tests/client/fast_render.js b/tests/client/fast_render.js index 48f7859..94b98a5 100644 --- a/tests/client/fast_render.js +++ b/tests/client/fast_render.js @@ -51,7 +51,7 @@ Tinytest.addAsync('FastRender - init - ObjectId support', function(test, done) { }); }); -Tinytest.add('FastRender - init - merge docs', function(test) { +Tinytest.addAsync('FastRender - init - merge docs', function(test, done) { var collName = Random.id(); var payload = { subscriptions: {posts: true}, @@ -69,16 +69,19 @@ Tinytest.add('FastRender - init - merge docs', function(test) { FastRender.init(payload); var coll = new Mongo.Collection(collName); - test.equal(coll.findOne('one'), { - _id: "one", - name: "arunoda", - age: 30, - city: "colombo", - plan: "pro" - }); + Meteor.setTimeout(function () { + test.equal(coll.findOne('one'), { + _id: "one", + name: "arunoda", + age: 30, + city: "colombo", + plan: "pro" + }); + done(); + }, bufferedWritesInterval); }); -Tinytest.add('FastRender - init - merge docs deep', function(test) { +Tinytest.addAsync('FastRender - init - merge docs deep', function(test, done) { var collName = Random.id(); var payload = { subscriptions: {posts: true}, @@ -95,18 +98,21 @@ Tinytest.add('FastRender - init - merge docs deep', function(test) { FastRender.init(payload); var coll = new Mongo.Collection(collName); - test.equal(coll.findOne('one'), { - _id: "one", - name: "arunoda", - profile: { + Meteor.setTimeout(function () { + test.equal(coll.findOne('one'), { + _id: "one", name: "arunoda", - email: "arunoda@arunoda.com" - } - }); + profile: { + name: "arunoda", + email: "arunoda@arunoda.com" + } + }); + done(); + }, bufferedWritesInterval); }); -Tinytest.add('FastRender - init - ejon data', function(test) { +Tinytest.addAsync('FastRender - init - ejon data', function(test, done) { var collName = Random.id(); var payload = { subscriptions: {posts: true}, @@ -123,8 +129,11 @@ Tinytest.add('FastRender - init - ejon data', function(test) { FastRender.init(payload); var coll = new Mongo.Collection(collName); - var doc = coll.findOne("one"); - test.equal(doc.date.getTime(), date.getTime()); + Meteor.setTimeout(function () { + var doc = coll.findOne("one"); + test.equal(doc.date.getTime(), date.getTime()); + done(); + }, bufferedWritesInterval); }); WithNewInjectDdpMessage = function(newCallback, runCode) { diff --git a/tests/utils.js b/tests/utils.js index e843e11..3c5a639 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -1,3 +1,5 @@ +bufferedWritesInterval = 5; + Tinytest.add('AddedToChanged - new fields', function(test) { var localCopy = {aa: 10}; var added = {fields: {aa: 20, bb: 20}, msg: 'added'}; From 2b3004d224004c97a221fa7507b3711ccdc5b533 Mon Sep 17 00:00:00 2001 From: Jesse Rosenberger Date: Thu, 21 Apr 2016 19:25:06 +0300 Subject: [PATCH 2/3] If the connection supports flushing the livedata buffer, do it. --- lib/client/fast_render.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/client/fast_render.js b/lib/client/fast_render.js index 5420c4b..315497b 100644 --- a/lib/client/fast_render.js +++ b/lib/client/fast_render.js @@ -56,6 +56,8 @@ FastRender.init = function(payload) { }); } + var connection = Meteor.connection; + _.each(allData, function(collData, collName) { _.each(collData, function(item, id) { var id = IDTools.idStringify(item._id); @@ -69,10 +71,13 @@ FastRender.init = function(payload) { frGen: true }; - FastRender.injectDdpMessage(Meteor.connection, ddpMessage); + FastRender.injectDdpMessage(connection, ddpMessage); }); }); + // If the connection supports buffered DDP writes, then flush now. + if (connection._flushBufferedWrites) connection._flushBufferedWrites(); + // let Meteor know, user login process has been completed if(typeof Accounts != 'undefined') { Accounts._setLoggingIn(false); From ff7ff6dd51680eebf2c667024f61625f5b9de185 Mon Sep 17 00:00:00 2001 From: Jesse Rosenberger Date: Thu, 21 Apr 2016 19:30:16 +0300 Subject: [PATCH 3/3] [Optional] The new livedata seems to handle waitForQuiescence fine ...As of meteor/meteor#5680. This can be left as it was though, and seems to work fine either way, though not overriding _waitingForQuiescence would be nice. --- lib/client/fast_render.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/client/fast_render.js b/lib/client/fast_render.js index 315497b..3793169 100644 --- a/lib/client/fast_render.js +++ b/lib/client/fast_render.js @@ -18,10 +18,17 @@ if(FastRender._disable) { // This is the cure FastRender.injectDdpMessage = function(conn, message) { FastRender["debugger"].log('injecting ddp message:', message); - var originalWait = conn._waitingForQuiescence; - conn._waitingForQuiescence = function() {return false}; - conn._livedata_data(message); - conn._waitingForQuiescence = originalWait; + if (conn._bufferedWrites) { + // New with meteor/meteor#5680 + // If the livedata connection supports buffered writes, + // we don't need check if we're in delay before injecting. + conn._livedata_data(message); + } else { + var originalWait = conn._waitingForQuiescence; + conn._waitingForQuiescence = function() {return false}; + conn._livedata_data(message); + conn._waitingForQuiescence = originalWait; + } }; FastRender.init = function(payload) {