Skip to content

Commit

Permalink
Mark messages as unsent when we reconnect. Sent means 'sent on this c…
Browse files Browse the repository at this point in the history
…onnection' not 'ever sent'. Fixes meteor#538.
  • Loading branch information
n1mmy committed Dec 19, 2012
1 parent e053201 commit 326b316
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/livedata/livedata_connection.js
Expand Up @@ -214,6 +214,12 @@ Meteor._LivedataConnection = function (url, options) {
self._outstandingMethodBlocks.shift();
}

// Mark all messages as unsent, they have not yet been sent on this
// connection.
_.each(self._methodInvokers, function (m) {
m.sentMessage = false;
});

// If an `onReconnect` handler is set, call it first. Go through
// some hoops to ensure that methods that are called from within
// `onReconnect` get executed _before_ ones that were originally
Expand Down
43 changes: 43 additions & 0 deletions packages/livedata/livedata_connection_tests.js
Expand Up @@ -1051,6 +1051,49 @@ Tinytest.add("livedata connection - onReconnect prepends messages correctly with
]);
});

Tinytest.add("livedata connection - onReconnect with sent messages", function(test) {
var stream = new Meteor._StubStream();
var conn = newConnection(stream);
startAndConnect(test, stream);

// setup method
conn.methods({do_something: function (x) {}});

conn.onReconnect = function() {
conn.apply('do_something', ['login'], {wait: true});
};

conn.apply('do_something', ['one']);

// initial connect
stream.sent = [];
stream.reset();
testGotMessage(
test, stream, {msg: 'connect', session: conn._lastSessionId});

// Test that we sent just the login message.
var loginId = testGotMessage(
test, stream, {msg: 'method', method: 'do_something',
params: ['login'], id: '*'});

// we connect.
stream.receive({msg: 'connected', session: Meteor.uuid()});
test.length(stream.sent, 0);

// login got result (but not yet data)
stream.receive({msg: 'result', id: loginId, result: 'foo'});
test.length(stream.sent, 0);

// login got data. now we send next method.
stream.receive({msg: 'data', methods: [loginId]});

testGotMessage(
test, stream, {msg: 'method', method: 'do_something',
params: ['one'], id: '*'});
});



Tinytest.add("livedata stub - reconnect double wait method", function (test) {
var stream = new Meteor._StubStream;
var conn = newConnection(stream);
Expand Down

0 comments on commit 326b316

Please sign in to comment.