<commit_before>import {expect, assert} from 'chai';
import {head, last, range} from 'ramda';

import {
    sqlConnections,
    elasticsearchConnections,
    publicReadableS3Connections,
    apacheDrillConnections,
    apacheDrillStorage,
    postgisConnection
} from './utils.js';

import {
    query, connect, files, storage, listS3Files, elasticsearchMappings
} from '../../backend/persistent/datastores/Datastores.js';

const transpose = m => m[0].map((x, i) => m.map(x => x[i]));


describe('SQL - ', function () {
    it('connect connects to a database', function(done) {
        this.timeout(4 * 1000);
        connect(sqlConnections).then(done).catch(done);
    });

    it('query queries a database', function(done) {
        this.timeout(4 * 1000);
        query(
            'SELECT * from ebola_2014 LIMIT 2',
            sqlConnections
        ).then(results => {
            assert.deepEqual(results.rows, [
                ['Guinea', 3, 14, '9.95', '-9.7', '122'],
                ['Guinea', 4, 14, '9.95', '-9.7', '224']
            ]);
            assert.deepEqual(results.columnnames, [
                'country', 'month', 'year', 'lat', 'lon', 'value'
            ]);
            done();
        }).catch(done);
    });

    /*
     * Unfortunately we don't have a PostGIS table that doesn't update
     * with random data yet, so we have to skip this test on CI.
     * It worked at a single point in time.
     * TODO - Create a static PostGIS table for testing
     */
    xit('query stringifies boolean, date, and geojson objects', function(done) {
        this.timeout(5 * 1000);

        query(
            'SELECT * from test LIMIT 1',
            postgisConnection
        ).then(results => {
            assert.deepEqual(
                results.rows,
                [[
                    1,
                    '2016-12-12T07:46:36.144Z',
                    'blue',
                    0,
                    0.641140648704853,
                    'true',
                    '{"type":"Point","coordinates":[7,9]}',
                    '{"type":"LineString","coordinates":[[6,6],[8,2],[7,5]]}',
                    '{"type":"Polygon","coordinates":[[[0,0],[3,0],[3,3],[0,3],[0,0]]]}',
                    '{"type":"MultiPoint","coordinates":[[0,1],[0,1]]}',
                    '{"type":"MultiLineString","coordinates":[[[3,8],[4,5],[9,5]],[[8,6],[4,8],[0,3]]]}',
                    '{"type":"MultiPolygon","coordinates":[[[[0,0],[7,0],[7,7],[0,7],[0,0]]],[[[0,0],[7,0],[7,7],[0,7],[0,0]]]]}',
                    '{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[9,8]},{"type":"Polygon","coordinates":[[[0,0],[7,0],[7,7],[0,7],[0,0]]]}]}'
                ]]
            );
            done();
        }).catch(done);
    });

});


describe('Elasticsearch - ', function () {
    it('connect connects to an index', function(done) {
        this.timeout(4 * 1000);
        connect(elasticsearchConnections).then(res => res.json().then(json => {
            assert.deepEqual(
                json[1],
                {
                    'health': 'yellow',
                    'status': 'open',
                    'index': 'plotly_datasets',
                    'pri': '1',
                    'rep': '1',
                    'docs.count': '28187',
                    'docs.deleted': '0',
                    'store.size': '5.8mb',
                    'pri.store.size': '5.8mb'<commit_msg>test mssql timeout errors<commit_after>import {expect, assert} from 'chai';
import {head, merge, last, range} from 'ramda';

import {
    sqlConnections,
    mssqlConnection,
    elasticsearchConnections,
    publicReadableS3Connections,
    apacheDrillConnections,
    apacheDrillStorage,
    postgisConnection
} from './utils.js';

import {
    query, connect, files, storage, listS3Files, elasticsearchMappings
} from '../../backend/persistent/datastores/Datastores.js';

const transpose = m => m[0].map((x, i) => m.map(x => x[i]));


describe('SQL - ', function () {
    it('connect connects to a database', function(done) {
        this.timeout(4 * 1000);
        connect(sqlConnections).then(done).catch(done);
    });

    it('query queries a database', function(done) {
        this.timeout(4 * 1000);
        query(
            'SELECT * from ebola_2014 LIMIT 2',
            sqlConnections
        ).then(results => {
            assert.deepEqual(results.rows, [
                ['Guinea', 3, 14, '9.95', '-9.7', '122'],
                ['Guinea', 4, 14, '9.95', '-9.7', '224']
            ]);
            assert.deepEqual(results.columnnames, [
                'country', 'month', 'year', 'lat', 'lon', 'value'
            ]);
            done();
        }).catch(done);
    });

    /*
     * Unfortunately we don't have a PostGIS table that doesn't update
     * with random data yet, so we have to skip this test on CI.
     * It worked at a single point in time.
     * TODO - Create a static PostGIS table for testing
     */
    xit('query stringifies boolean, date, and geojson objects', function(done) {
        this.timeout(5 * 1000);

        query(
            'SELECT * from test LIMIT 1',
            postgisConnection
        ).then(results => {
            assert.deepEqual(
                results.rows,
                [[
                    1,
                    '2016-12-12T07:46:36.144Z',
                    'blue',
                    0,
                    0.641140648704853,
                    'true',
                    '{"type":"Point","coordinates":[7,9]}',
                    '{"type":"LineString","coordinates":[[6,6],[8,2],[7,5]]}',
                    '{"type":"Polygon","coordinates":[[[0,0],[3,0],[3,3],[0,3],[0,0]]]}',
                    '{"type":"MultiPoint","coordinates":[[0,1],[0,1]]}',
                    '{"type":"MultiLineString","coordinates":[[[3,8],[4,5],[9,5]],[[8,6],[4,8],[0,3]]]}',
                    '{"type":"MultiPolygon","coordinates":[[[[0,0],[7,0],[7,7],[0,7],[0,0]]],[[[0,0],[7,0],[7,7],[0,7],[0,0]]]]}',
                    '{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[9,8]},{"type":"Polygon","coordinates":[[[0,0],[7,0],[7,7],[0,7],[0,0]]]}]}'
                ]]
            );
            done();
        }).catch(done);
    });

});


describe('MSSQL - ', function () {
    it('times out after 15 seconds by default', function(done) {
        this.timeout(20 * 1000);
        query(
            'WAITFOR DELAY \'00:00:16\'',
            mssqlConnection
        ).then(() => {
            done('Was supposed to fail');
        }).catch(e => {
            assert.equal(
                e.message,
                'Timeout: Request failed to complete in 15000ms'
            );
            done();
        }).catch(done);
    });

    it('doesn\'t timeout if requestTimeout was set', function(done) {
        this.timeout(20 * 1000);
        query(
            'WAITFOR DELAY \'00:00:16\'',
            merge(mssqlConnection, {requestTimeout: 18 * 1000})
        ).then(() => {
            done();
        }).catch(done);
    });
});

describe('Elasticsearch - ', function () {
    it('connect connects to an index', function(done) {
        this.timeout(4 * 1000);
        connect(elasticsearchConnections).then(res => res.json().then(json => {
            assert.deepEqual(
                json[1],
                {
                    'health': 'yellow',
                    'status': 'open',
                    'index': 'plotly_datasets',
                    'pri': '1',
                    'rep': '1',
                    'docs.count': '28187',
                    'docs.deleted': '0',
                    'store.size': '5.8mb',
                    'pri.store.size': '5.8mb'
{'fraction_non_alphanumeric': 0.18789603000129315, 'fraction_numerical': 0.0474589421957843, 'mean_word_length': 1.8021739130434782, 'pattern_counts': {'":': 36, '<': 3, '<?xml version=': 0, '>': 20, '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': '5085901', 'n_tokens_mistral': 2573, 'n_tokens_neox': 2288, 'n_words': 438}