Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
co(function*() {
const primaryServer = yield mock.createServer(32000, 'localhost');
const firstSecondaryServer = yield mock.createServer(32001, 'localhost');
const secondSecondaryServer = yield mock.createServer(32002, 'localhost');
primaryServer.setMessageHandler(request => {
var doc = request.document;
// Fail primary
if (step >= 1) return;
if (doc.ismaster) {
request.reply(primary[currentIsMasterIndex]);
}
});
firstSecondaryServer.setMessageHandler(request => {
var doc = request.document;
if (doc.ismaster) {
request.reply(firstSecondary[currentIsMasterIndex]);
co(function*() {
const primaryServer = yield mock.createServer(32000, 'localhost');
const firstSecondaryServer = yield mock.createServer(32001, 'localhost');
const secondSecondaryServer = yield mock.createServer(32002, 'localhost');
primaryServer.setMessageHandler(request => {
var doc = request.document;
// Stop responding to any calls (emulate dropping packets on the floor)
if (stopRespondingPrimary) {
delay(3000).then(() => handleMessage(doc));
} else {
handleMessage(doc);
}
function handleMessage(doc) {
if (doc.ismaster && currentIsMasterState === 0) {
request.reply(primary[currentIsMasterState]);
} else if (doc.insert && currentIsMasterState === 0) {
co(function*() {
const server = yield mock.createServer();
server.setMessageHandler(request => {
var doc = request.document;
if (doc.ismaster && currentStep === 0) {
request.reply(serverIsMaster[0]);
currentStep += 1;
} else if (doc.insert && currentStep === 1) {
// Stop responding to any calls (emulate dropping packets on the floor)
if (stopRespondingPrimary) {
currentStep += 1;
stopRespondingPrimary = false;
setTimeout(() => request.connection.destroy(), 1500);
}
} else if (doc.ismaster) {
request.reply(serverIsMaster[0]);
beforeEach(() => {
return mock.createServer().then(mockServer => {
test.server = mockServer;
});
});
beforeEach(() => {
return mock.createServer().then(mockServer => {
test.server = mockServer;
});
});
beforeEach(() => {
return mock.createServer().then(mockServer => {
test.server = mockServer;
});
});
beforeEach(() => {
return mock.createServer().then(mockServer => {
test.server = mockServer;
});
});
beforeEach(() => {
return mock.createServer().then(mockServer => {
test.server = mockServer;
test.connectOptions = {
host: test.server.host,
port: test.server.port,
bson: new BSON(),
credentials: new MongoCredentials({
username: 'testUser',
password: 'pencil',
source: 'admin',
mechanism: 'plain'
})
};
});
});
co(function*() {
const primaryServer = yield mock.createServer(32000, 'localhost');
const firstSecondaryServer = yield mock.createServer(32001, 'localhost');
const secondSecondaryServer = yield mock.createServer(32003, 'localhost');
const arbiterServer = yield mock.createServer(32002, 'localhost');
primaryServer.setMessageHandler(request => {
var doc = request.document;
if (doc.ismaster) {
request.reply(primary[currentIsMasterIndex]);
}
});
firstSecondaryServer.setMessageHandler(request => {
var doc = request.document;
if (doc.ismaster) {
request.reply(firstSecondary[currentIsMasterIndex]);
}
});
co(function*() {
const primaryServer = yield mock.createServer(32000, 'localhost');
const firstSecondaryServer = yield mock.createServer(32001, 'localhost');
const secondSecondaryServer = yield mock.createServer(32003, 'localhost');
const arbiterServer = yield mock.createServer(32002, 'localhost');
primaryServer.setMessageHandler(request => {
var doc = request.document;
if (doc.ismaster) {
request.reply(primary[currentIsMasterIndex]);
}
});
firstSecondaryServer.setMessageHandler(request => {
var doc = request.document;
if (doc.ismaster) {
request.reply(firstSecondary[currentIsMasterIndex]);
}
});