<commit_before>'use strict';
var test = require('./shared').assert;
var setupDatabase = require('./shared').setupDatabase;

describe('SDAM', function() {
  before(function() {
    return setupDatabase(this.configuration);
  });

  it('Should correctly emit all Replicaset SDAM operations', {
    metadata: { requires: { topology: 'replicaset' } },

    // The actual test we wish to run
    test: function(done) {
      var configuration = this.configuration;
      var operations = {
        serverDescriptionChanged: [],
        serverHeartbeatStarted: [],
        serverHeartbeatSucceeded: [],
        serverOpening: [],
        serverClosed: [],
        topologyOpening: [],
        topologyDescriptionChanged: [],
        topologyClosed: []
      };

      var client = configuration.newClient();
      var events = [
        'serverDescriptionChanged',
        'serverHeartbeatStarted',
        'serverHeartbeatSucceeded',
        'serverOpening',
        'serverClosed',
        'topologyOpening',
        'topologyDescriptionChanged',
        'topologyClosed'
      ];
      events.forEach(function(e) {
        client.on(e, function(result) {
          operations[e].push(result);
        });
      });

      client.connect(function(err) {
        test.equal(null, err);

        client.close(true, function() {
          for (var name in operations) {
            test.ok(operations[name].length > 0);
          }

          done();
        });
      });
    }
  });

  it('Should correctly emit all Mongos SDAM operations', {
    metadata: { requires: { topology: 'sharded' } },

    // The actual test we wish to run
    test: function(done) {
      var configuration = this.configuration;
      var operations = {
        serverDescriptionChanged: [],
        serverHeartbeatStarted: [],<commit_msg>test(sdam): add a wait for sdam events to come in<commit_after>'use strict';
var test = require('./shared').assert;
var setupDatabase = require('./shared').setupDatabase;

describe('SDAM', function() {
  before(function() {
    return setupDatabase(this.configuration);
  });

  it('Should correctly emit all Replicaset SDAM operations', {
    metadata: { requires: { topology: 'replicaset' } },

    // The actual test we wish to run
    test: function(done) {
      var configuration = this.configuration;
      var operations = {
        serverDescriptionChanged: [],
        serverHeartbeatStarted: [],
        serverHeartbeatSucceeded: [],
        serverOpening: [],
        serverClosed: [],
        topologyOpening: [],
        topologyDescriptionChanged: [],
        topologyClosed: []
      };

      var client = configuration.newClient();
      var events = [
        'serverDescriptionChanged',
        'serverHeartbeatStarted',
        'serverHeartbeatSucceeded',
        'serverOpening',
        'serverClosed',
        'topologyOpening',
        'topologyDescriptionChanged',
        'topologyClosed'
      ];
      events.forEach(function(e) {
        client.on(e, function(result) {
          operations[e].push(result);
        });
      });

      client.connect(function(err) {
        test.equal(null, err);

        client.close(true, function() {
          setTimeout(() => {
            for (var name in operations) {
              test.ok(operations[name].length > 0);
            }

            done();
          }, 1000);
        });
      });
    }
  });

  it('Should correctly emit all Mongos SDAM operations', {
    metadata: { requires: { topology: 'sharded' } },

    // The actual test we wish to run
    test: function(done) {
      var configuration = this.configuration;
      var operations = {
        serverDescriptionChanged: [],
        serverHeartbeatStarted: [],
{'fraction_non_alphanumeric': 0.12772250605001345, 'fraction_numerical': 0.0016133369185264857, 'mean_word_length': 2.336322869955157, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '336358', 'n_tokens_mistral': 1020, 'n_tokens_neox': 970, 'n_words': 217}