<commit_before>/* Test the Ephemeral socket
 */

var EphemeralSocket = require('../lib/EphemeralSocket'),
    FakeServer = require('./FakeServer'),
    assert = require('chai').assert;

/*global describe before it after*/

describe('EphemeralSocket', function () {
    var s, e;

    before(function (done) {
        s = new FakeServer();
        e = new EphemeralSocket();

        s.start(done);
    });

    after(function () {
        s.stop();
    });

    it("Respects host-configuration", function (done) {
        var w = new EphemeralSocket({host: 'some_other_host.sbhr.dk'});
        w.send('wrong_message');

        setTimeout(function () {
            assert.lengthOf(s._packetsReceived, 0);
            done();
        }, 25);
    });


    it("Convert the port to integer", function () {
        var testSocket = new EphemeralSocket({port: "1234"});
        assert.strictEqual(testSocket._port, 1234);
    });

    it("Sends data immediately with maxBufferSize = 0", function (done) {
        var withoutBuffer = new EphemeralSocket({maxBufferSize: 0}),
            start = Date.now();

        withoutBuffer.send('do_not_buffer');

        s.expectMessage('do_not_buffer', function (err) {
            assert.closeTo(Date.now() - start, 0, 5);
            withoutBuffer.close();
            done(err);
        });
    });

    it("Doesn't send data immediately with maxBufferSize > 0", function (done) {
        var withBuffer = new EphemeralSocket({socketTimeout: 25});
        withBuffer.send('buffer_this');
        var start = Date.now();
<commit_msg>EphemeralSocket test: Accept a higher latency (see #72 for context)<commit_after>/* Test the Ephemeral socket
 */

var EphemeralSocket = require('../lib/EphemeralSocket'),
    FakeServer = require('./FakeServer'),
    assert = require('chai').assert;

/*global describe before it after*/

describe('EphemeralSocket', function () {
    var s, e;

    before(function (done) {
        s = new FakeServer();
        e = new EphemeralSocket();

        s.start(done);
    });

    after(function () {
        s.stop();
    });

    it("Respects host-configuration", function (done) {
        var w = new EphemeralSocket({host: 'some_other_host.sbhr.dk'});
        w.send('wrong_message');

        setTimeout(function () {
            assert.lengthOf(s._packetsReceived, 0);
            done();
        }, 25);
    });


    it("Convert the port to integer", function () {
        var testSocket = new EphemeralSocket({port: "1234"});
        assert.strictEqual(testSocket._port, 1234);
    });

    it("Sends data immediately with maxBufferSize = 0", function (done) {
        var withoutBuffer = new EphemeralSocket({maxBufferSize: 0}),
            start = Date.now();

        withoutBuffer.send('do_not_buffer');

        s.expectMessage('do_not_buffer', function (err) {
            assert.closeTo(Date.now() - start, 0, 20);
            withoutBuffer.close();
            done(err);
        });
    });

    it("Doesn't send data immediately with maxBufferSize > 0", function (done) {
        var withBuffer = new EphemeralSocket({socketTimeout: 25});
        withBuffer.send('buffer_this');
        var start = Date.now();

{'fraction_non_alphanumeric': 0.1445104785736628, 'fraction_numerical': 0.012198936502971536, 'mean_word_length': 2.5298013245033113, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7356465', 'n_tokens_mistral': 1002, 'n_tokens_neox': 916, 'n_words': 217}