<commit_before>'use strict';

const utils = require('./utils');

const assert = require('assert');
const crypto = require('crypto');
const r = require('rethinkdb');

const all_tests = (table) => {
  beforeEach('authenticate', (done) => utils.fusion_default_auth(done));

  // Launch simultaneous queries that depend on a non-existent table, then
  // verify that only one table exists with that name.
  it('table create race on read', (done) => {
    const query_count = 5;
    const table_name = crypto.randomBytes(8).toString('hex');

    let finished = 0;
    for (let i = 0; i < query_count; ++i) {
      utils.stream_test(
        { request_id: i, type: 'query', options: { collection: table_name } },
        (err, res) => {
          assert.ifError(err);
          assert.strictEqual(res.length, 0);
          if (++finished === query_count) {
            r.table(table_name).count().run(utils.rdb_conn())
             .then((count) => (assert.strictEqual(count, 0), done()),
                   (error) => done(error));
          }
        });
    }
  });

  // Same as the previous test, but it exists because the ReQL error message
  // is different for a read or a write when the table is unavailable.
  it('table create race on write', (done) => {
    const query_count = 5;
    const table_name = crypto.randomBytes(8).toString('hex');

    let finished = 0;
    for (let i = 0; i < query_count; ++i) {
      utils.stream_test(
        {
          request_id: i,
          type: 'insert',
          options: {
            collection: table_name,
            data: [ { } ],
          },
        },
        (err, res) => {
          assert.ifError(err);
          assert.strictEqual(res.length, 1);
          if (++finished === query_count) {
            r.table(table_name).count().run(utils.rdb_conn())
             .then((count) => (assert.strictEqual(count, query_count), done()),
                   (error) => done(error));
          }
        });
    }
  });

  // Launch two simultaneous queries that depend on a non-existent index, then
  // verify that only one such index exists with that name.
  it('index create race', (done) => {
    const query_count = 5;
    const field_name = crypto.randomBytes(8).toString('hex');
    const conn = utils.rdb_conn();

    r.table(table).indexStatus().count().run(conn).then((old_count) => {
      let finished = 0;
      for (let i = 0; i < query_count; ++i) {
        utils.stream_test(
          {
            request_id: i,
            type: 'query',
            options: {
              collection: table,
              order: [ [ field_name ], 'ascending' ],
            },
          },
          (err, res) => {
            assert.ifError(err);
            assert.strictEqual(res.length, 0);
            if (++finished === query_count) {
              r.table(table).indexStatus().count().run(conn).then((new_count) => {
                 assert.strictEqual(old_count + 1, new_count);
                 done();
              }, (err) => done(err));
            }
          });<commit_msg>fixed last broken server test<commit_after>'use strict';

const utils = require('./utils');

const assert = require('assert');
const crypto = require('crypto');
const r = require('rethinkdb');

const all_tests = (table) => {
  beforeEach('clear table', (done) => utils.clear_table(table, done));
  beforeEach('authenticate', (done) => utils.fusion_default_auth(done));

  // Launch simultaneous queries that depend on a non-existent table, then
  // verify that only one table exists with that name.
  it('table create race on read', (done) => {
    const query_count = 5;
    const table_name = crypto.randomBytes(8).toString('hex');

    let finished = 0;
    for (let i = 0; i < query_count; ++i) {
      utils.stream_test(
        { request_id: i, type: 'query', options: { collection: table_name } },
        (err, res) => {
          assert.ifError(err);
          assert.strictEqual(res.length, 0);
          if (++finished === query_count) {
            r.table(table_name).count().run(utils.rdb_conn())
             .then((count) => (assert.strictEqual(count, 0), done()),
                   (error) => done(error));
          }
        });
    }
  });

  // Same as the previous test, but it exists because the ReQL error message
  // is different for a read or a write when the table is unavailable.
  it('table create race on write', (done) => {
    const query_count = 5;
    const table_name = crypto.randomBytes(8).toString('hex');

    let finished = 0;
    for (let i = 0; i < query_count; ++i) {
      utils.stream_test(
        {
          request_id: i,
          type: 'insert',
          options: {
            collection: table_name,
            data: [ { } ],
          },
        },
        (err, res) => {
          assert.ifError(err);
          assert.strictEqual(res.length, 1);
          if (++finished === query_count) {
            r.table(table_name).count().run(utils.rdb_conn())
             .then((count) => (assert.strictEqual(count, query_count), done()),
                   (error) => done(error));
          }
        });
    }
  });

  // Launch two simultaneous queries that depend on a non-existent index, then
  // verify that only one such index exists with that name.
  it('index create race', (done) => {
    const query_count = 5;
    const field_name = crypto.randomBytes(8).toString('hex');
    const conn = utils.rdb_conn();

    r.table(table).indexStatus().count().run(conn).then((old_count) => {
      let finished = 0;
      for (let i = 0; i < query_count; ++i) {
        utils.stream_test(
          {
            request_id: i,
            type: 'query',
            options: {
              collection: table,
              order: [ [ field_name ], 'ascending' ],
            },
          },
          (err, res) => {
            assert.ifError(err);
            assert.strictEqual(res.length, 0);
            if (++finished === query_count) {
              r.table(table).indexStatus().count().run(conn).then((new_count) => {
                assert.strictEqual(old_count + 1, new_count);
                done();
              }, (err) => done(err));
            }
          });
{'fraction_non_alphanumeric': 0.14994344805299725, 'fraction_numerical': 0.005493617708838262, 'mean_word_length': 2.0313418217433887, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 34, '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': '746102', 'n_tokens_mistral': 1847, 'n_tokens_neox': 1789, 'n_words': 463}