<commit_before>var test = require('tap').test;
var http = require('http');
var net = require('net');
var bouncy = require('../');

var listening = (function () {
    var pending = 2;
    return function () {
        if (--pending === 0) runTest();
    };
})();

var server = http.createServer(function (req, res) {
    res.setHeader('content-type', 'text/plain');
    res.write('beep boop');
    res.end();
});
server.listen(0, listening);
var port = server.address().port;

var bs = bouncy(function (req, bounce) {
    bounce(port);
});
bs.listen(0, listening);
var bport = bs.address().port;

function flurry (t, cb) {
    var pending = 50;
    for (var i = 0; i < 50; i++) {
        check(t, function () {
            if (--pending === 0) cb();
        });
    }
}

function runTest () {
    test('check for leaks', function (t) {
        t.plan(50 * 2 + 1);
        
        flurry(t, function () {
            var baseline = process.memoryUsage();
            flurry(t, function () {
                var mark = process.memoryUsage();
                t.ok(baseline.heapUsed * 1.1 < mark.heapUsed);
            });
        });
        
        t.on('end', function () {
            server.close();
            bs.close();
        });
    });
}

function check (t, cb) {
    var opts = {
        path : '/',
        port : bport<commit_msg>larger batch size, leak test still passes<commit_after>var test = require('tap').test;
var http = require('http');
var net = require('net');
var bouncy = require('../');

var listening = (function () {
    var pending = 2;
    return function () {
        if (--pending === 0) runTest();
    };
})();

var server = http.createServer(function (req, res) {
    res.setHeader('content-type', 'text/plain');
    res.write('beep boop');
    res.end();
});
server.listen(0, listening);
var port = server.address().port;

var bs = bouncy(function (req, bounce) {
    bounce(port);
});
bs.listen(0, listening);
var bport = bs.address().port;

var batchSize = 400;

function flurry (t, cb) {
    var pending = batchSize;
    for (var i = 0; i < batchSize; i++) {
        check(t, function () {
            if (--pending === 0) cb();
        });
    }
}

function runTest () {
    test('check for leaks', function (t) {
        t.plan(batchSize * 2 + 1);
        
        flurry(t, function () {
            var baseline = process.memoryUsage();
            flurry(t, function () {
                var mark = process.memoryUsage();
                t.ok(baseline.heapUsed * 1.1 < mark.heapUsed);
            });
        });
        
        t.on('end', function () {
            server.close();
            bs.close();
        });
    });
}

function check (t, cb) {
    var opts = {
        path : '/',
        port : bport
{'fraction_non_alphanumeric': 0.1782214156079855, 'fraction_numerical': 0.010526315789473684, 'mean_word_length': 1.9956521739130435, 'pattern_counts': {'":': 0, '<': 7, '<?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': '7606973', 'n_tokens_mistral': 910, 'n_tokens_neox': 863, 'n_words': 220}