How to use mongodb-mock-server - 10 common examples

To help you get started, we’ve selected a few mongodb-mock-server examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mongodb / node-mongodb-native / test / core / functional / rs_mocks / primary_loses_network_tests.js View on Github external
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]);
github mongodb / node-mongodb-native / test / core / functional / rs_mocks / monitoring_tests.js View on Github external
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) {
github mongodb / node-mongodb-native / test / core / functional / mongos_mocks / single_proxy_connection_tests.js View on Github external
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]);
github mongodb / node-mongodb-native / test / core / unit / mongos / events_tests.js View on Github external
beforeEach(() => {
    return mock.createServer().then(mockServer => {
      test.server = mockServer;
    });
  });
github mongodb / node-mongodb-native / test / core / unit / pool_tests.js View on Github external
beforeEach(() => {
    return mock.createServer().then(mockServer => {
      test.server = mockServer;
    });
  });
github mongodb / node-mongodb-native / test / core / unit / single / sessions_tests.js View on Github external
beforeEach(() => {
    return mock.createServer().then(mockServer => {
      test.server = mockServer;
    });
  });
github mongodb / node-mongodb-native / test / core / unit / scram_iterations_tests.js View on Github external
beforeEach(() => {
    return mock.createServer().then(mockServer => {
      test.server = mockServer;
    });
  });
github mongodb / node-mongodb-native / test / core / unit / connect_tests.js View on Github external
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'
        })
      };
    });
  });
github mongodb / node-mongodb-native / test / core / functional / rs_mocks / maintanance_mode_tests.js View on Github external
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]);
          }
        });
github mongodb / node-mongodb-native / test / core / functional / rs_mocks / add_remove_tests.js View on Github external
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]);
          }
        });

mongodb-mock-server

A mock server useful for testing difficult to reproduce cases in MongoDB drivers

Apache-2.0
Latest version published 5 years ago

Package Health Score

36 / 100
Full package analysis