From 0a3146d88dab68137160367d9c8da18e4e29cc9a Mon Sep 17 00:00:00 2001 From: Naomi Seyfer Date: Tue, 9 Apr 2013 11:56:22 -0700 Subject: [PATCH] nim comments the last --- .../livedata/livedata_connection_tests.js | 57 +++++++++---------- packages/livedata/livedata_tests.js | 20 +++++++ packages/livedata/stream_client_common.js | 14 +---- packages/livedata/stream_client_nodejs.js | 11 ++-- packages/livedata/stream_client_sockjs.js | 2 - packages/livedata/stream_tests.js | 4 +- 6 files changed, 57 insertions(+), 51 deletions(-) diff --git a/packages/livedata/livedata_connection_tests.js b/packages/livedata/livedata_connection_tests.js index 6beaaf8254..831b41554d 100644 --- a/packages/livedata/livedata_connection_tests.js +++ b/packages/livedata/livedata_connection_tests.js @@ -1,5 +1,4 @@ -var identity = function () {return arguments;}; var newConnection = function (stream) { // Some of these tests leave outstanding methods with no result yet // returned. This should not block us from re-running tests when sources @@ -276,7 +275,7 @@ Tinytest.add("livedata stub - this", function (test) { }}); // should throw no exceptions - conn.call('test_this', identity); + conn.call('test_this', _.identity); // satisfy method, quiesce connection var message = JSON.parse(stream.sent.shift()); test.equal(message, {msg: 'method', method: 'test_this', @@ -399,7 +398,7 @@ Tinytest.add("livedata stub - mutating method args", function (test) { arg.foo = 42; }}); - conn.call('mutateArgs', {foo: 50}, identity); + conn.call('mutateArgs', {foo: 50}, _.identity); // Method should be called with original arg, not mutated arg. var message = JSON.parse(stream.sent.shift()); @@ -451,7 +450,7 @@ Tinytest.add("livedata stub - methods calling methods", function (test) { var o = observeCursor(test, coll.find()); // call method. - conn.call('do_something', identity); + conn.call('do_something', _.identity); // see we only send message for outer methods var message = JSON.parse(stream.sent.shift()); @@ -560,8 +559,8 @@ Tinytest.add("livedata stub - reconnect", function (test) { methodCallbackFired = true; }); - conn.apply('do_something_else', [], {wait: true}, identity); - conn.apply('do_something_later', [], identity); + conn.apply('do_something_else', [], {wait: true}, _.identity); + conn.apply('do_something_later', [], _.identity); test.isFalse(methodCallbackFired); @@ -922,7 +921,7 @@ Tinytest.add("livedata stub - multiple stubs same doc", function (test) { test.equal(coll.find().count(), 0); // Call the insert method. - conn.call('insertSomething', identity); + conn.call('insertSomething', _.identity); // Stub write is visible. test.equal(coll.find({foo: 'bar'}).count(), 1); var stubWrittenId = coll.findOne({foo: 'bar'})._id; @@ -934,7 +933,7 @@ Tinytest.add("livedata stub - multiple stubs same doc", function (test) { test.equal(stream.sent.length, 0); // Call update method. - conn.call('updateIt', stubWrittenId, identity); + conn.call('updateIt', stubWrittenId, _.identity); // This stub write is visible too. test.equal(coll.find().count(), 1); test.equal(coll.findOne(stubWrittenId), @@ -1003,11 +1002,11 @@ Tinytest.add("livedata stub - unsent methods don't block quiescence", function ( test.equal(coll.find().count(), 0); // Call a random method (no-op) - conn.call('no-op', identity); + conn.call('no-op', _.identity); // Call a wait method - conn.apply('no-op', [], {wait: true}, identity); + conn.apply('no-op', [], {wait: true}, _.identity); // Call a method with a stub that writes. - conn.call('insertSomething', identity); + conn.call('insertSomething', _.identity); // Stub write is visible. @@ -1247,15 +1246,15 @@ Tinytest.add("livedata connection - onReconnect prepends messages correctly with conn.methods({do_something: function (x) {}}); conn.onReconnect = function() { - conn.apply('do_something', ['reconnect zero'], identity); - conn.apply('do_something', ['reconnect one'], identity); - conn.apply('do_something', ['reconnect two'], {wait: true}, identity); - conn.apply('do_something', ['reconnect three'], identity); + conn.apply('do_something', ['reconnect zero'], _.identity); + conn.apply('do_something', ['reconnect one'], _.identity); + conn.apply('do_something', ['reconnect two'], {wait: true}, _.identity); + conn.apply('do_something', ['reconnect three'], _.identity); }; - conn.apply('do_something', ['one'], identity); - conn.apply('do_something', ['two'], {wait: true}, identity); - conn.apply('do_something', ['three'], identity); + conn.apply('do_something', ['one'], _.identity); + conn.apply('do_something', ['two'], {wait: true}, _.identity); + conn.apply('do_something', ['three'], _.identity); // reconnect stream.sent = []; @@ -1332,15 +1331,15 @@ Tinytest.add("livedata connection - onReconnect prepends messages correctly with conn.methods({do_something: function (x) {}}); conn.onReconnect = function() { - conn.apply('do_something', ['reconnect one'], identity); - conn.apply('do_something', ['reconnect two'], identity); - conn.apply('do_something', ['reconnect three'], identity); + conn.apply('do_something', ['reconnect one'], _.identity); + conn.apply('do_something', ['reconnect two'], _.identity); + conn.apply('do_something', ['reconnect three'], _.identity); }; - conn.apply('do_something', ['one'], identity); - conn.apply('do_something', ['two'], {wait: true}, identity); - conn.apply('do_something', ['three'], {wait: true}, identity); - conn.apply('do_something', ['four'], identity); + conn.apply('do_something', ['one'], _.identity); + conn.apply('do_something', ['two'], {wait: true}, _.identity); + conn.apply('do_something', ['three'], {wait: true}, _.identity); + conn.apply('do_something', ['four'], _.identity); // reconnect stream.sent = []; @@ -1376,10 +1375,10 @@ Tinytest.add("livedata connection - onReconnect with sent messages", function(te conn.methods({do_something: function (x) {}}); conn.onReconnect = function() { - conn.apply('do_something', ['login'], {wait: true}, identity); + conn.apply('do_something', ['login'], {wait: true}, _.identity); }; - conn.apply('do_something', ['one'], identity); + conn.apply('do_something', ['one'], _.identity); // initial connect stream.sent = []; @@ -1469,7 +1468,7 @@ Tinytest.add("livedata stub - reconnect double wait method", function (test) { // Call another method. It should be delivered immediately. This is a // regression test for a case where it never got delivered because there was // an empty block in _outstandingMethodBlocks blocking it from being sent. - conn.call('lastMethod', identity); + conn.call('lastMethod', _.identity); testGotMessage(test, stream, {msg: 'method', method: 'lastMethod', params: [], id: '*'}); }); @@ -1529,7 +1528,7 @@ Tinytest.add("livedata stub - stubs before connected", function (test) { test.length(stream.sent, 0); // Insert a document. The stub updates "conn" directly. - coll.insert({_id: "foo", bar: 42}, identity); + coll.insert({_id: "foo", bar: 42}, _.identity); test.equal(coll.find().count(), 1); test.equal(coll.findOne(), {_id: "foo", bar: 42}); // It also sends the method message. diff --git a/packages/livedata/livedata_tests.js b/packages/livedata/livedata_tests.js index ef18c55cdc..8e3ca9292c 100644 --- a/packages/livedata/livedata_tests.js +++ b/packages/livedata/livedata_tests.js @@ -627,6 +627,26 @@ if (Meteor.isServer) { ]); })(); +if (Meteor.isServer) { + (function () { + var conn; + testAsyncMulti("livedata - method call on server blocks in a fiber way", [ + function (test, expect) { + conn = Meteor.connect(Meteor.absoluteUrl()); + Meteor.setTimeout(expect(function () { + test.isTrue(conn.status().connected, "Not connected"); + }), 500); + }, + + function (test, expect) { + if (conn.status().connected) { + test.equal(conn.call('s2s', 'foo'), "s2s foo"); + } + } + ]); + })(); +} + (function () { var conn; testAsyncMulti("livedata - connect fails to unknown place", [ diff --git a/packages/livedata/stream_client_common.js b/packages/livedata/stream_client_common.js index c40ac573a3..f2c3b9e51f 100644 --- a/packages/livedata/stream_client_common.js +++ b/packages/livedata/stream_client_common.js @@ -108,9 +108,7 @@ _.extend(Meteor._DdpClientStream.prototype, { self.currentStatus = { status: "connecting", connected: false, - retryCount: 0, - // XXX Backwards compatibility only. Remove this before 1.0. - retry_count: 0 + retryCount: 0 }; @@ -147,8 +145,6 @@ _.extend(Meteor._DdpClientStream.prototype, { clearTimeout(self.retryTimer); self.retryTimer = null; self.currentStatus.retryCount -= 1; // don't count manual retries - // XXX Backwards compatibility only. Remove this before 1.0. - self.currentStatus.retry_count = self.currentStatus.retryCount; self._retryNow(); }, @@ -164,8 +160,6 @@ _.extend(Meteor._DdpClientStream.prototype, { self.currentStatus = { status: "failed", connected: false, - retryCount: 0, - // XXX Backwards compatibility only. Remove this before 1.0. retryCount: 0 }; if (optionalErrorMessage) @@ -208,8 +202,6 @@ _.extend(Meteor._DdpClientStream.prototype, { self.currentStatus.status = "waiting"; self.currentStatus.connected = false; self.currentStatus.retryTime = (new Date()).getTime() + timeout; - // XXX Backwards compatibility only. Remove this before 1.0. - self.currentStatus.retry_time = self.currentStatus.retryTime; self.statusChanged(); }, @@ -220,13 +212,9 @@ _.extend(Meteor._DdpClientStream.prototype, { return; self.currentStatus.retryCount += 1; - // XXX Backwards compatibility only. Remove this before 1.0. - self.currentStatus.retry_count = self.currentStatus.retryCount; self.currentStatus.status = "connecting"; self.currentStatus.connected = false; delete self.currentStatus.retryTime; - // XXX Backwards compatibility only. Remove this before 1.0. - delete self.currentStatus.retry_time; self.statusChanged(); self._launchConnection(); diff --git a/packages/livedata/stream_client_nodejs.js b/packages/livedata/stream_client_nodejs.js index fb7a55f2b5..312d755205 100644 --- a/packages/livedata/stream_client_nodejs.js +++ b/packages/livedata/stream_client_nodejs.js @@ -8,12 +8,13 @@ var WebSocketClient = Npm.require('websocket').client; // "http://subdomain.meteor.com/" or "/" or // "ddp+sockjs://foo-**.meteor.com/sockjs" // -// -> Unlike the client, we require something of the form 'mysite.com', -// which we will map to 'ws(s)://mysite.com/websocket' +// We do some rewriting of the URL to eventually make it "ws://" or "wss://", +// whatever was passed in. At the very least, what Meteor.absoluteUrl() returns +// us should work. // -// We don't do any heartbeating. (The logic that did this in sockjs -// was removed, because it used a built-in sockjs mechanism. We could -// do it with WebSocket ping frames or with DDP-level messages.) +// We don't do any heartbeating. (The logic that did this in sockjs was removed, +// because it used a built-in sockjs mechanism. We could do it with WebSocket +// ping frames or with DDP-level messages.) Meteor._DdpClientStream = function (endpoint) { var self = this; diff --git a/packages/livedata/stream_client_sockjs.js b/packages/livedata/stream_client_sockjs.js index 5182b62e7e..607b3c37b2 100644 --- a/packages/livedata/stream_client_sockjs.js +++ b/packages/livedata/stream_client_sockjs.js @@ -75,8 +75,6 @@ _.extend(Meteor._DdpClientStream.prototype, { self.currentStatus.status = "connected"; self.currentStatus.connected = true; self.currentStatus.retryCount = 0; - // XXX Backwards compatibility only. Remove before 1.0. - self.currentStatus.retry_count = self.currentStatus.retryCount; self.statusChanged(); // fire resets. This must come after status change so that clients diff --git a/packages/livedata/stream_tests.js b/packages/livedata/stream_tests.js index 22cc0eedf3..ffd8798c64 100644 --- a/packages/livedata/stream_tests.js +++ b/packages/livedata/stream_tests.js @@ -5,8 +5,8 @@ Tinytest.add("stream - status", function (test) { test.equal(typeof status, "object"); test.isTrue(status.status); // Make sure backward-compatiblity names are defined. - test.equal(status.retryCount, status.retry_count); - test.equal(status.retryTime, status.retry_time); + test.equal(status.retryCount, status.retryCount); + test.equal(status.retryTime, status.retryTime); }); testAsyncMulti("stream - reconnect", [