<commit_before>'use strict';

const assert = require('assert');
const Promise = require('bluebird');
const elasticsearch = require('elasticsearch');
const lib = require('../Elasticsearch');
const Err = require('@kartotherian/err');

/**
 * This test will attempt to connect to the elasticsearch instance runnign on the localhost.
 * Each test will create a new index (verifying that it doesn't already exist), and cleanup afterwards.
 */
describe('Tests', function() {

  Promise.config({
    warnings: true,
    longStackTraces: true
  });

  const host = 'localhost:9200';
  const log = 'error'; // 'debug';
  const esClient = new elasticsearch.Client({host/*, log*/});

  const tilelive = {
    protocols: {}
  };

  lib.registerProtocols(tilelive);

  function createIndexName() {
    let prefix = 'tiletest';
    let indexCount = 0;

    const tryOne = () => {
      const index = prefix + (indexCount ? `_${indexCount}` : '');
      return esClient.indices.exists({index})
        .then((exists) => {
          if (!exists) return index;
          indexCount++;
          return tryOne();
        });
    };

    return esClient.ping().catch(err => {
      throw new Error(`Unable to PING localhost elasticsearch instance. Is it running?\n     ${err}`);
    }).then(tryOne);
  }

  function cleanup(index) {
    if (index === undefined) {
      return Promise.resolve();
    }
    return esClient.indices
      .delete({index})
      .catch(
        (err) => console.error('Cleanup failed', err)
      );
  }

  function runTest(testFunc) {
    let index;<commit_msg>test err message<commit_after>'use strict';

const assert = require('assert');
const Promise = require('bluebird');
const elasticsearch = require('elasticsearch');
const lib = require('../Elasticsearch');
const Err = require('@kartotherian/err');

/**
 * This test will attempt to connect to the elasticsearch instance runnign on the localhost.
 * Each test will create a new index (verifying that it doesn't already exist), and cleanup afterwards.
 */
describe('Tests', function() {

  Promise.config({
    warnings: true,
    longStackTraces: true
  });

  const host = 'localhost:9200';
  const log = 'error'; // 'debug';
  const esClient = new elasticsearch.Client({host/*, log*/});

  const tilelive = {
    protocols: {}
  };

  lib.registerProtocols(tilelive);

  function createIndexName() {
    let prefix = 'tiletest';
    let indexCount = 0;

    const tryOne = () => {
      const index = prefix + (indexCount ? `_${indexCount}` : '');
      return esClient.indices.exists({index})
        .then((exists) => {
          if (!exists) return index;
          indexCount++;
          return tryOne();
        });
    };

    return esClient.ping().catch(err => {
      throw new Error(`Unable to PING elasticsearch instance at ${host}. Is it running?\n     ${err}`);
    }).then(tryOne);
  }

  function cleanup(index) {
    if (index === undefined) {
      return Promise.resolve();
    }
    return esClient.indices
      .delete({index})
      .catch(
        (err) => console.error('Cleanup failed', err)
      );
  }

  function runTest(testFunc) {
    let index;
{'fraction_non_alphanumeric': 0.14634920634920634, 'fraction_numerical': 0.0031746031746031746, 'mean_word_length': 2.9785353535353534, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '1721524', 'n_tokens_mistral': 922, 'n_tokens_neox': 899, 'n_words': 260}