mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
cleaning up server to server connection tests
This commit is contained in:
@@ -607,18 +607,19 @@ if (Meteor.isServer) {
|
||||
});
|
||||
}
|
||||
(function () {
|
||||
var conn;
|
||||
testAsyncMulti("livedata - connect works from both client and server", [
|
||||
function (test, expect) {
|
||||
conn = Meteor.connect(Meteor.absoluteUrl());
|
||||
Meteor.setTimeout(expect(function () {
|
||||
test.isTrue(conn.status().connected, "Not connected");
|
||||
}), 500);
|
||||
var self = this;
|
||||
self.conn = Meteor.connect(Meteor.absoluteUrl());
|
||||
pollUntil(expect, function () {
|
||||
return self.conn.status().connected;
|
||||
}, 10000);
|
||||
},
|
||||
|
||||
function (test, expect) {
|
||||
if (conn.status().connected) {
|
||||
conn.call('s2s', 'foo', expect(function (err, res) {
|
||||
var self = this;
|
||||
if (self.conn.status().connected) {
|
||||
self.conn.call('s2s', 'foo', expect(function (err, res) {
|
||||
if (err)
|
||||
throw err;
|
||||
test.equal(res, "s2s foo");
|
||||
@@ -630,18 +631,19 @@ 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);
|
||||
var self = this;
|
||||
self.conn = Meteor.connect(Meteor.absoluteUrl());
|
||||
pollUntil(expect, function () {
|
||||
return self.conn.status().connected;
|
||||
}, 10000);
|
||||
},
|
||||
|
||||
function (test, expect) {
|
||||
if (conn.status().connected) {
|
||||
test.equal(conn.call('s2s', 'foo'), "s2s foo");
|
||||
var self = this;
|
||||
if (self.conn.status().connected) {
|
||||
test.equal(self.conn.call('s2s', 'foo'), "s2s foo");
|
||||
}
|
||||
}
|
||||
]);
|
||||
@@ -649,12 +651,12 @@ if (Meteor.isServer) {
|
||||
}
|
||||
|
||||
(function () {
|
||||
var conn;
|
||||
testAsyncMulti("livedata - connect fails to unknown place", [
|
||||
function (test, expect) {
|
||||
conn = Meteor.connect("example.com");
|
||||
var self = this;
|
||||
self.conn = Meteor.connect("example.com");
|
||||
Meteor.setTimeout(expect(function () {
|
||||
test.isFalse(conn.status().connected, "Not connected");
|
||||
test.isFalse(self.conn.status().connected, "Not connected");
|
||||
}), 500);
|
||||
}
|
||||
]);
|
||||
|
||||
@@ -836,9 +836,9 @@ if (Meteor.isServer) {
|
||||
});
|
||||
|
||||
self.conn = Meteor.connect(Meteor.absoluteUrl());
|
||||
Meteor.setTimeout(expect(function () {
|
||||
test.isTrue(self.conn.status().connected, "Not connected");
|
||||
}), 500);
|
||||
pollUntil(expect, function () {
|
||||
return self.conn.status().connected;
|
||||
}, 10000);
|
||||
},
|
||||
|
||||
function (test, expect) {
|
||||
|
||||
@@ -151,3 +151,23 @@ _.extend(ExpectationManager.prototype, {
|
||||
runNext();
|
||||
});
|
||||
};
|
||||
|
||||
/*global*/
|
||||
|
||||
pollUntil = function (expect, f, timeout, step) {
|
||||
step = step || 100;
|
||||
var expectation = expect(true);
|
||||
var start = (new Date()).valueOf();
|
||||
var helper = function () {
|
||||
if (f()) {
|
||||
expectation(true);
|
||||
return;
|
||||
}
|
||||
if (start + timeout < (new Date()).valueOf()) {
|
||||
expectation(false);
|
||||
return;
|
||||
}
|
||||
Meteor.setTimeout(helper, step);
|
||||
};
|
||||
helper();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user