0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/pummel/test-net-connect-memleak.js
Roman Reiss f29762f4dd test: enable linting for tests
Enable linting for the test directory. A number of changes was made so
all tests conform the current rules used by lib and src directories. The
only exception for tests is that unreachable (dead) code is allowed.

test-fs-non-number-arguments-throw had to be excluded from the changes
because of a weird issue on Windows CI.

PR-URL: https://github.com/nodejs/io.js/pull/1721
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-05-19 21:21:27 +02:00

33 lines
831 B
JavaScript

'use strict';
// Flags: --expose-gc
var common = require('../common');
var assert = require('assert');
var net = require('net');
assert(typeof gc === 'function', 'Run this test with --expose-gc');
net.createServer(function() {}).listen(common.PORT);
var before = 0;
(function() {
// 2**26 == 64M entries
gc();
for (var i = 0, junk = [0]; i < 26; ++i) junk = junk.concat(junk);
before = process.memoryUsage().rss;
net.createConnection(common.PORT, '127.0.0.1', function() {
assert(junk.length != 0); // keep reference alive
setTimeout(done, 10);
gc();
});
})();
function done() {
gc();
var after = process.memoryUsage().rss;
var reclaimed = (before - after) / 1024;
console.log('%d kB reclaimed', reclaimed);
assert(reclaimed > 128 * 1024); // It's around 256 MB on x64.
process.exit();
}