<commit_before>import { Db, MongoClient } from 'mongodb';
import MongoMemoryServer from '../MongoMemoryServer';

jasmine.DEFAULT_TIMEOUT_INTERVAL = 600000;

let con1: MongoClient;
let con2: MongoClient;
let db1: Db;
let db2: Db;
let mongoServer1: MongoMemoryServer;
let mongoServer2: MongoMemoryServer;

beforeAll(async () => {
  mongoServer1 = await MongoMemoryServer.create();
  const mongoUri = mongoServer1.getUri();
  con1 = await MongoClient.connect(mongoUri, {
    useNewUrlParser: true,
    useUnifiedTopology: true,
  });

  db1 = con1.db(mongoServer1.getDbName());

  mongoServer2 = await MongoMemoryServer.create();
  const mongoUri2 = mongoServer2.getUri();
  con2 = await MongoClient.connect(mongoUri2, {
    useNewUrlParser: true,
    useUnifiedTopology: true,
  });

  db2 = con2.db(mongoServer1.getDbName());
});

afterAll(async () => {
  if (con1) {
    await con1.close();
  }
  if (con2) {
    await con2.close();
  }
  if (mongoServer1) {
    await mongoServer1.stop();
  }
  if (mongoServer2) {
    await mongoServer2.stop();
  }
});

describe('Multiple mongoServers', () => {
  it('should start several servers', async () => {
    expect(db1).toBeDefined();
    const col1 = db1.collection('test');
    const result1 = await col1.insertMany([{ a: 1 }, { b: 1 }]);
    expect(result1.result).toMatchSnapshot();
    expect(await col1.countDocuments({})).toBe(2);

    expect(db2).toBeDefined();
    const col2 = db2.collection('test');
    const result2 = await col2.insertMany([{ a: 2 }, { b: 2 }]);
    expect(result2.result).toMatchSnapshot();
    expect(await col2.countDocuments({})).toBe(2);
  });

  it('should have different uri', () => {
    const uri1 = mongoServer1.getUri();
    const uri2 = mongoServer2.getUri();
    expect(uri1).not.toEqual(uri2);
  });

  it('v6.0.0 adds "?" to the connection string (uri)', () => {
    const uri1 = mongoServer1.getUri();
    expect(uri1.includes('?')).toBeTruthy();
  });
});
<commit_msg>test(multipleDB): move "beforeAll" and "afterAll" hooks inside describe<commit_after>import { Db, MongoClient } from 'mongodb';
import MongoMemoryServer from '../MongoMemoryServer';

jasmine.DEFAULT_TIMEOUT_INTERVAL = 600000;

describe('Multiple mongoServers', () => {
  let con1: MongoClient;
  let con2: MongoClient;
  let db1: Db;
  let db2: Db;
  let mongoServer1: MongoMemoryServer;
  let mongoServer2: MongoMemoryServer;

  beforeAll(async () => {
    mongoServer1 = await MongoMemoryServer.create();
    const mongoUri = mongoServer1.getUri();
    con1 = await MongoClient.connect(mongoUri, {
      useNewUrlParser: true,
      useUnifiedTopology: true,
    });

    db1 = con1.db(mongoServer1.getDbName());

    mongoServer2 = await MongoMemoryServer.create();
    const mongoUri2 = mongoServer2.getUri();
    con2 = await MongoClient.connect(mongoUri2, {
      useNewUrlParser: true,
      useUnifiedTopology: true,
    });

    db2 = con2.db(mongoServer1.getDbName());
  });

  afterAll(async () => {
    if (con1) {
      await con1.close();
    }
    if (con2) {
      await con2.close();
    }
    if (mongoServer1) {
      await mongoServer1.stop();
    }
    if (mongoServer2) {
      await mongoServer2.stop();
    }
  });

  it('should start several servers', async () => {
    expect(db1).toBeDefined();
    const col1 = db1.collection('test');
    const result1 = await col1.insertMany([{ a: 1 }, { b: 1 }]);
    expect(result1.result).toMatchSnapshot();
    expect(await col1.countDocuments({})).toBe(2);

    expect(db2).toBeDefined();
    const col2 = db2.collection('test');
    const result2 = await col2.insertMany([{ a: 2 }, { b: 2 }]);
    expect(result2.result).toMatchSnapshot();
    expect(await col2.countDocuments({})).toBe(2);
  });

  it('should have different uri', () => {
    const uri1 = mongoServer1.getUri();
    const uri2 = mongoServer2.getUri();
    expect(uri1).not.toEqual(uri2);
  });

  it('v6.0.0 adds "?" to the connection string (uri)', () => {
    const uri1 = mongoServer1.getUri();
    expect(uri1.includes('?')).toBeTruthy();
  });
});

{'fraction_non_alphanumeric': 0.15925925925925927, 'fraction_numerical': 0.03259259259259259, 'mean_word_length': 3.7214452214452214, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '375909', 'n_tokens_mistral': 1456, 'n_tokens_neox': 1404, 'n_words': 279}