<commit_before>'use strict';

// This is a client that produces load on hodor-net-server.

process.title = 'nodejs hodor client';

var net = require('net');

var BACKOFF = 1000;

function next() {
    var connected = false;
    var finished = false;
    var data = "";

    var client = net.connect(+process.env.HODOR_PORT, 'localhost', function () {
        connected = true;
    });

    client.setEncoding('utf-8');

    client.on('error', function (error) {
        console.log('unexpected error', error.message);
        setTimeout(next, BACKOFF);
    });
    client.on('data', function (_data) {
        data += _data;
    });
    client.on('finish', function () {
        finished = true;
    });
    client.on('end', function () {
        if (!connected) {
            console.log('unexpected end before connection');
            setTimeout(next, BACKOFF);
        } else if (data !== 'HODOR') {
            console.log('unexpected response', data);
            setTimeout(next, BACKOFF);
        } else if (!finished) {
            console.log('expected finish before end');
            setTimeout(next, BACKOFF);
        } else {
            next();
        }
    });

}

// Five concurrent requests
next();
next();
next();
next();
next();
<commit_msg>Use debuglog for test client<commit_after>'use strict';

// This is a client that produces load on hodor-net-server.

process.title = 'nodejs hodor client';

var net = require('net');
var debuglog = require('debuglog');
var log = debuglog('hodor-net-client');

var BACKOFF = 1000;

function next() {
    var connected = false;
    var finished = false;
    var data = "";

    var client = net.connect(+process.env.HODOR_PORT, 'localhost', function () {
        connected = true;
    });

    client.setEncoding('utf-8');

    client.on('error', function (error) {
        log('unexpected error', error.message);
        setTimeout(next, BACKOFF);
    });
    client.on('data', function (_data) {
        data += _data;
    });
    client.on('finish', function () {
        finished = true;
    });
    client.on('end', function () {
        if (!connected) {
            log('unexpected end before connection');
            setTimeout(next, BACKOFF);
        } else if (data !== 'HODOR') {
            log('unexpected response', JSON.stringify(data));
            setTimeout(next, BACKOFF);
        } else if (!finished) {
            log('expected finish before end');
            setTimeout(next, BACKOFF);
        } else {
            next();
        }
    });

}

// Five concurrent requests
next();
next();
next();
next();
next();

{'fraction_non_alphanumeric': 0.15429011158137745, 'fraction_numerical': 0.003847633705271258, 'mean_word_length': 2.341902313624679, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1845542', 'n_tokens_mistral': 769, 'n_tokens_neox': 743, 'n_words': 198}