Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
os: linux
language: node_js
node_js:
- "0.10"
- "0.12"
- "4"
- "6"
- "8"
Expand Down
8 changes: 7 additions & 1 deletion lib/topologies/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,13 @@ function Timeout(fn, time) {

this.start = function () {
if (!this.isRunning()) {
timer = setTimeout(fn, time);
timer = setTimeout(function() {
fn();
if (timer && timer._called === undefined) {
// The artificial _called is set here for compatibility with node.js 0.10.x/0.12.x versions
timer._called = true;
}
}, time);
}
return this;
};
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"require_optional": "~1.0.0"
},
"devDependencies": {
"request": "2.65.0",
"co": "^4.5.4",
"coveralls": "^2.11.6",
"es6-promise": "^3.0.2",
Expand Down
59 changes: 36 additions & 23 deletions test/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,30 +196,43 @@ var runner = new Runner({
, failFast: true
});

var testFiles = [
var testFiles = [];

try {
eval("(function *(){})");

// Functional tests
'/test/tests/functional/pool_tests.js',
'/test/tests/functional/server_tests.js',
'/test/tests/functional/cursor_tests.js',
'/test/tests/functional/extend_cursor_tests.js',
'/test/tests/functional/undefined_tests.js',
'/test/tests/functional/tailable_cursor_tests.js',
'/test/tests/functional/error_tests.js',
'/test/tests/functional/operations_tests.js',
'/test/tests/functional/operation_example_tests.js',
'/test/tests/functional/basic_single_server_auth_tests.js',
'/test/tests/functional/basic_replset_server_auth_tests.js',
'/test/tests/functional/replset_tests.js',
// Replicaset SDAM tests
'/test/tests/functional/replset_state_tests.js',
// Replicaset Server selection tests
'/test/tests/functional/replset_server_selection_tests.js',
'/test/tests/functional/mongos_server_selection_tests.js',
// Replicaset max staleness tests
'/test/tests/functional/max_staleness_tests.js',
// Client Metadata test
'/test/tests/functional/client_metadata_tests.js'
]
testFiles.push('/test/tests/functional/pool_tests.js')
} catch(err) {}

// Functional tests
testFiles.push('/test/tests/functional/server_tests.js');
testFiles.push('/test/tests/functional/cursor_tests.js');
testFiles.push('/test/tests/functional/extend_cursor_tests.js');
testFiles.push('/test/tests/functional/undefined_tests.js');
testFiles.push('/test/tests/functional/tailable_cursor_tests.js');
testFiles.push('/test/tests/functional/error_tests.js');
testFiles.push('/test/tests/functional/operations_tests.js');
testFiles.push('/test/tests/functional/operation_example_tests.js');
testFiles.push('/test/tests/functional/basic_single_server_auth_tests.js');
testFiles.push('/test/tests/functional/basic_replset_server_auth_tests.js');
testFiles.push('/test/tests/functional/replset_tests.js');

// Replicaset monitoring tests
testFiles.push('/test/tests/functional/monitoring_tests.js');

// Replicaset SDAM tests
testFiles.push('/test/tests/functional/replset_state_tests.js');

// Replicaset Server selection tests
testFiles.push('/test/tests/functional/replset_server_selection_tests.js');
testFiles.push('/test/tests/functional/mongos_server_selection_tests.js');

// Replicaset max staleness tests
testFiles.push('/test/tests/functional/max_staleness_tests.js');

// Client Metadata test
testFiles.push('/test/tests/functional/client_metadata_tests.js');

// Check if we support es6 generators
try {
Expand Down
147 changes: 147 additions & 0 deletions test/tests/functional/monitoring_tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
"use strict";
var assign = require('../../../lib/utils').assign;

var timeoutPromise = function(timeout) {
return new Promise(function(resolve, reject) {
setTimeout(function() {
resolve();
}, timeout);
});
}

exports['Should not create excessive amount of Timeouts in intervalIds array'] = {
metadata: {
requires: {
// generators: true,
topology: "single"
}
},

test: function(configuration, test) {
var ReplSet = configuration.require.ReplSet,
ObjectId = configuration.require.BSON.ObjectId,
// Connection = require('../../../lib/connection/connection'),
// co = require('co'),
mockupdb = require('../../mock');

// Contain mock server
var primaryServer = null;
var firstSecondaryServer = null;
var secondSecondaryServer = null;
var running = true;
var electionIds = [new ObjectId(), new ObjectId()];
// Current index for the ismaster
var currentIsMasterState = 0;
// Primary stop responding
var stopRespondingPrimary = false;

// Default message fields
var defaultFields = {
"setName": "rs", "setVersion": 1, "electionId": electionIds[currentIsMasterState],
"maxBsonObjectSize" : 16777216, "maxMessageSizeBytes" : 48000000,
"maxWriteBatchSize" : 1000, "localTime" : new Date(), "maxWireVersion" : 3,
"minWireVersion" : 0, "ok" : 1, "hosts": ["localhost:32000", "localhost:32001", "localhost:32002"]
}

// Primary server states
var primary = [assign({}, defaultFields, {
"ismaster":true, "secondary":false, "me": "localhost:32000", "primary": "localhost:32000"
}), assign({}, defaultFields, {
"ismaster":false, "secondary":true, "me": "localhost:32000", "primary": "localhost:32001"
})];

// Primary server states
var firstSecondary = [assign({}, defaultFields, {
"ismaster":false, "secondary":true, "me": "localhost:32001", "primary": "localhost:32000"
}), assign({}, defaultFields, {
"ismaster":true, "secondary":false, "me": "localhost:32001", "primary": "localhost:32001"
})];

// Primary server states
var secondSecondary = [assign({}, defaultFields, {
"ismaster":false, "secondary":true, "me": "localhost:32002", "primary": "localhost:32000"
}), assign({}, defaultFields, {
"ismaster":false, "secondary":true, "me": "localhost:32002", "primary": "localhost:32001"
})];

// Boot the mock
Promise.all([
mockupdb.createServer(32000, 'localhost').then(function(server) { primaryServer = server; }),
mockupdb.createServer(32001, 'localhost').then(function(server) { firstSecondaryServer = server; }),
mockupdb.createServer(32002, 'localhost').then(function(server) { secondSecondaryServer = server; })
]).then(function() {
function runInfinitely(fn) {
return primaryServer.receive().then(function(request) {
if (fn(request)) { return runInfinitely(fn); }
});
}

// Primary state machine
runInfinitely(function(request) {
var doc = request.document;

if(doc.ismaster && currentIsMasterState == 0) {
request.reply(primary[currentIsMasterState]);
}
return running;
})

// First secondary state machine
runInfinitely(function(request) {
var doc = request.document;

if(doc.ismaster) {
request.reply(firstSecondary[currentIsMasterState]);
}
return running;
});

// Second secondary state machine
runInfinitely(function(request) {
var doc = request.document;

if(doc.ismaster) {
request.reply(secondSecondary[currentIsMasterState]);
}
return running;
});

});

// Attempt to connect
var server = new ReplSet([
{ host: 'localhost', port: 32000 },
{ host: 'localhost', port: 32001 },
{ host: 'localhost', port: 32002 }], {
setName: 'rs',
connectionTimeout: 5000,
socketTimeout: 60000,
haInterval: 200,
size: 1
});

// Add event listeners
server.on('connect', function(_server) {
setTimeout(function() {
console.dir("Total amount of Timeout instances running: " + _server.intervalIds.length);
test.ok(_server.intervalIds.length === 3);

// Destroy mock
primaryServer.destroy();
firstSecondaryServer.destroy();
secondSecondaryServer.destroy();
server.destroy();
running = false;

test.equal(0, _server.intervalIds.length);

test.done();
}, 5000);
});

// Gives proxies a chance to boot up
setTimeout(function() {
server.connect();
}, 100)
}
}
6 changes: 3 additions & 3 deletions test/tests/functional/pool_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ exports['Should only listen on connect once'] = {

// Add event listeners
pool.on('connect', function(_pool) {
process.nextTick(() => {
process.nextTick(function() {
// Now that we are in next tick, connection should still exist, but there
// should be no connect listeners
test.equal(0, connection.connection.listenerCount('connect'));
test.equal(0, connection.connection.listeners('connect').length);
test.equal(1, pool.allConnections().length);

_pool.destroy();
Expand All @@ -82,7 +82,7 @@ exports['Should only listen on connect once'] = {

test.equal(1, pool.allConnections().length);
connection = pool.allConnections()[0];
test.equal(1, connection.connection.listenerCount('connect'));
test.equal(1, connection.connection.listeners('connect').length);
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/tests/functional/rs_mocks/maintanance_mode_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ exports['Successfully detect server in maintanance mode'] = {
// Primary server states
var secondSecondary = [assign({}, defaultFields, {
"ismaster":false, "secondary":true, "me": "localhost:32003", "primary": "localhost:32000", "tags" : { "loc" : "sf" }
}), { "ismaster" : true,
}), {
"ismaster":false, "secondary":false, "arbiterOnly": false, "me": "localhost:32003", "primary": "localhost:32000", "tags" : { "loc" : "sf" }
}];

Expand Down