Skip to content

Commit

Permalink
test,tools: limit lint tolerance of gc global
Browse files Browse the repository at this point in the history
Lint rules permitted the `gc` global in any test file. This change
limits it to just the files that need it.

PR-URL: nodejs#6324
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
  • Loading branch information
Trott committed Apr 29, 2016
1 parent 2e845f8 commit 6c49714
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 36 deletions.
3 changes: 0 additions & 3 deletions test/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@
rules:
## common module is mandatory in tests
required-modules: [2, "common"]

globals:
gc: false
6 changes: 3 additions & 3 deletions test/addons/buffer-free-callback/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ function check(size, alignment, offset) {
buf = null;
binding.check(slice);
slice = null;
gc();
gc();
gc();
global.gc();
global.gc();
global.gc();
}

check(64, 1, 0);
Expand Down
2 changes: 1 addition & 1 deletion test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ var knownGlobals = [setTimeout,
global];

if (global.gc) {
knownGlobals.push(gc);
knownGlobals.push(global.gc);
}

if (global.DTRACE_HTTP_SERVER_RESPONSE) {
Expand Down
4 changes: 2 additions & 2 deletions test/gc/test-http-client-connaborted.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ function afterGC() {

var timer;
function statusLater() {
gc();
global.gc();
if (timer) clearTimeout(timer);
timer = setTimeout(status, 1);
}

function status() {
gc();
global.gc();
console.log('Done: %d/%d', done, todo);
console.log('Collected: %d/%d', countGC, count);
if (done === todo) {
Expand Down
4 changes: 2 additions & 2 deletions test/gc/test-http-client-onerror.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ function afterGC() {

var timer;
function statusLater() {
gc();
global.gc();
if (timer) clearTimeout(timer);
timer = setTimeout(status, 1);
}

function status() {
gc();
global.gc();
console.log('Done: %d/%d', done, todo);
console.log('Collected: %d/%d', countGC, count);
if (done === todo) {
Expand Down
4 changes: 2 additions & 2 deletions test/gc/test-http-client-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ function afterGC() {

var timer;
function statusLater() {
gc();
global.gc();
if (timer) clearTimeout(timer);
timer = setTimeout(status, 1);
}

function status() {
gc();
global.gc();
console.log('Done: %d/%d', done, todo);
console.log('Collected: %d/%d', countGC, count);
if (done === todo) {
Expand Down
4 changes: 2 additions & 2 deletions test/gc/test-http-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function getall() {
res.resume();
console.error('in cb');
done += 1;
res.on('end', gc);
res.on('end', global.gc);
}

var req = http.get({
Expand All @@ -57,7 +57,7 @@ function afterGC() {
setInterval(status, 1000).unref();

function status() {
gc();
global.gc();
console.log('Done: %d/%d', done, todo);
console.log('Collected: %d/%d', countGC, count);
if (done === todo) {
Expand Down
6 changes: 3 additions & 3 deletions test/gc/test-net-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function getall() {
//console.log('timeout (expected)')
req.destroy();
done++;
gc();
global.gc();
});

count++;
Expand All @@ -63,13 +63,13 @@ function afterGC() {
setInterval(status, 100).unref();

function status() {
gc();
global.gc();
console.log('Done: %d/%d', done, todo);
console.log('Collected: %d/%d', countGC, count);
if (done === todo) {
/* Give libuv some time to make close callbacks. */
setTimeout(function() {
gc();
global.gc();
console.log('All should be collected now.');
console.log('Collected: %d/%d', countGC, count);
assert(count === countGC);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-parser-bad-ref.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var messagesComplete = 0;

function flushPool() {
Buffer.allocUnsafe(Buffer.poolSize - 1);
gc();
global.gc();
}

function demoBug(part1, part2) {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-vm-create-and-run-in-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ assert.equal('lala', context.thing);
console.error('run in contextified sandbox without referencing the context');
var sandbox = {x: 1};
vm.createContext(sandbox);
gc();
global.gc();
vm.runInContext('x = 2', sandbox);
// Should not crash.
4 changes: 2 additions & 2 deletions test/parallel/test-vm-run-in-new-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const common = require('../common');
const assert = require('assert');
const vm = require('vm');

assert.equal(typeof gc, 'function', 'Run this test with --expose-gc');
assert.equal(typeof global.gc, 'function', 'Run this test with --expose-gc');

common.globalCheck = false;

Expand Down Expand Up @@ -48,6 +48,6 @@ assert.equal(f.a, 2);

console.error('use function in context without referencing context');
var fn = vm.runInNewContext('(function() { obj.p = {}; })', { obj: {} });
gc();
global.gc();
fn();
// Should not crash
8 changes: 4 additions & 4 deletions test/pummel/test-net-connect-memleak.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ var common = require('../common');
var assert = require('assert');
var net = require('net');

assert(typeof gc === 'function', 'Run this test with --expose-gc');
assert(typeof global.gc === 'function', 'Run this test with --expose-gc');
net.createServer(function() {}).listen(common.PORT);

var before = 0;
(function() {
// 2**26 == 64M entries
gc();
global.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();
global.gc();
});
})();

function done() {
gc();
global.gc();
var after = process.memoryUsage().rss;
var reclaimed = (before - after) / 1024;
console.log('%d kB reclaimed', reclaimed);
Expand Down
2 changes: 1 addition & 1 deletion test/pummel/test-regress-GH-814.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var timeToQuit = Date.now() + 8e3; //Test during no more than this seconds.

if (PASS) {
fs.write(testFileFD, newBuffer(kBufSize, 0x61), 0, kBufSize, -1, cb);
gc();
global.gc();
var nuBuf = Buffer.allocUnsafe(kBufSize);
neverWrittenBuffer.copy(nuBuf);
if (bufPool.push(nuBuf) > 100) {
Expand Down
12 changes: 6 additions & 6 deletions test/pummel/test-regress-GH-814_2.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ function writer() {
}, 555);
} else {
fs.write(testFD, newBuffer(kBufSize, 0x61), 0, kBufSize, -1, writerCB);
gc();
gc();
gc();
gc();
gc();
gc();
global.gc();
global.gc();
global.gc();
global.gc();
global.gc();
global.gc();
var nuBuf = Buffer.allocUnsafe(kBufSize);
neverWrittenBuffer.copy(nuBuf);
if (bufPool.push(nuBuf) > 100) {
Expand Down
6 changes: 3 additions & 3 deletions test/pummel/test-tls-connect-memleak.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var tls = require('tls');

var fs = require('fs');

assert(typeof gc === 'function', 'Run this test with --expose-gc');
assert(typeof global.gc === 'function', 'Run this test with --expose-gc');

tls.createServer({
cert: fs.readFileSync(common.fixturesDir + '/test_cert.pem'),
Expand All @@ -27,13 +27,13 @@ tls.createServer({
tls.connect(common.PORT, '127.0.0.1', options, function() {
assert(junk.length != 0); // keep reference alive
setTimeout(done, 10);
gc();
global.gc();
});
})();

function done() {
var before = process.memoryUsage().rss;
gc();
global.gc();
var after = process.memoryUsage().rss;
var reclaimed = (before - after) / 1024;
console.log('%d kB reclaimed', reclaimed);
Expand Down

0 comments on commit 6c49714

Please sign in to comment.