<commit_before>'use strict'

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

module.exports.name = 'Prereqs';

module.exports.prepare_database = (done) => done();

module.exports.all_tests = () => { };<commit_msg>adding test for race condition in prereqs<commit_after>'use strict'

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

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

const table = 'prereq_test';

module.exports.name = 'Prereqs';

module.exports.prepare_database = (done) => {
  var c = utils.rdb_conn();
  r.tableCreate(table).run(c)
   .then((res) => {
        assert.equal(res.tables_created, 1);
        done();
      });
};

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

      var finished = 0;
      var collector = () => {
          if (++finished == query_count) {
            r.table(table_name).count().run(utils.rdb_conn())
             .then((res) => (assert.equal(res, 0), done()),
                   (err) => done(err));
          }
        };

      for (var i = 0; i < query_count; ++i) {
        utils.stream_test(
          { request_id: i, type: 'query', options: { collection: table_name } },
          (err, res) => {
            assert.ifError(err);
            assert.equal(res.length, 0);
            collector();
          });
      }
    });

  // Launch two simultaneous queries that depend on a non-existent table, then
  // verify that only one table exists with that name.
  it('index create race', (done) => {
      var index_name = crypto.randomBytes(6).toString('base64');
      done();
    });
};
{'fraction_non_alphanumeric': 0.1616602949208083, 'fraction_numerical': 0.006553795740032769, 'mean_word_length': 2.5711500974658867, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 14, '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': '4010505', 'n_tokens_mistral': 572, 'n_tokens_neox': 554, 'n_words': 140}