Skip to content

Commit

Permalink
test: don't call process.exit() in gc tests
Browse files Browse the repository at this point in the history
Rewrite the tests in test/gc so that they no longer call process.exit().
Instead they exit gracefully now.

PR-URL: #11239
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
  • Loading branch information
bnoordhuis authored and italoacasas committed Feb 13, 2017
1 parent d1bbb6c commit a3a6892
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 56 deletions.
15 changes: 2 additions & 13 deletions test/gc/test-http-client-connaborted.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ function serverHandler(req, res) {

const http = require('http');
const weak = require('weak');
const assert = require('assert');
const todo = 500;
let done = 0;
let count = 0;
Expand All @@ -28,7 +27,6 @@ function getall() {
(function() {
function cb(res) {
done += 1;
statusLater();
}

const req = http.get({
Expand All @@ -51,20 +49,11 @@ function afterGC() {
countGC++;
}

let timer;
function statusLater() {
global.gc();
if (timer) clearTimeout(timer);
timer = setTimeout(status, 1);
}
setInterval(status, 100).unref();

function status() {
global.gc();
console.log('Done: %d/%d', done, todo);
console.log('Collected: %d/%d', countGC, count);
if (done === todo) {
console.log('All should be collected now.');
assert.strictEqual(count, countGC);
process.exit(0);
}
if (countGC === todo) server.close();
}
15 changes: 2 additions & 13 deletions test/gc/test-http-client-onerror.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ function serverHandler(req, res) {

const http = require('http');
const weak = require('weak');
const assert = require('assert');
const todo = 500;
let done = 0;
let count = 0;
Expand All @@ -31,7 +30,6 @@ function getall() {
function cb(res) {
res.resume();
done += 1;
statusLater();
}
function onerror(er) {
throw er;
Expand Down Expand Up @@ -59,20 +57,11 @@ function afterGC() {
countGC++;
}

let timer;
function statusLater() {
global.gc();
if (timer) clearTimeout(timer);
timer = setTimeout(status, 1);
}
setInterval(status, 100).unref();

function status() {
global.gc();
console.log('Done: %d/%d', done, todo);
console.log('Collected: %d/%d', countGC, count);
if (done === todo) {
console.log('All should be collected now.');
assert.strictEqual(count, countGC);
process.exit(0);
}
if (countGC === todo) server.close();
}
15 changes: 2 additions & 13 deletions test/gc/test-http-client-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ function serverHandler(req, res) {

const http = require('http');
const weak = require('weak');
const assert = require('assert');
const todo = 550;
let done = 0;
let count = 0;
Expand All @@ -33,7 +32,6 @@ function getall() {
function cb(res) {
res.resume();
done += 1;
statusLater();
}

const req = http.get({
Expand All @@ -60,20 +58,11 @@ function afterGC() {
countGC++;
}

let timer;
function statusLater() {
global.gc();
if (timer) clearTimeout(timer);
timer = setTimeout(status, 1);
}
setInterval(status, 100).unref();

function status() {
global.gc();
console.log('Done: %d/%d', done, todo);
console.log('Collected: %d/%d', countGC, count);
if (done === todo) {
console.log('All should be collected now.');
assert.strictEqual(count, countGC);
process.exit(0);
}
if (countGC === todo) server.close();
}
9 changes: 2 additions & 7 deletions test/gc/test-http-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ function serverHandler(req, res) {

const http = require('http');
const weak = require('weak');
const assert = require('assert');
const todo = 500;
let done = 0;
let count = 0;
Expand Down Expand Up @@ -54,15 +53,11 @@ function afterGC() {
countGC++;
}

setInterval(status, 1000).unref();
setInterval(status, 100).unref();

function status() {
global.gc();
console.log('Done: %d/%d', done, todo);
console.log('Collected: %d/%d', countGC, count);
if (done === todo) {
console.log('All should be collected now.');
assert.strictEqual(count, countGC);
process.exit(0);
}
if (countGC === todo) server.close();
}
11 changes: 1 addition & 10 deletions test/gc/test-net-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,5 @@ function status() {
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() {
global.gc();
console.log('All should be collected now.');
console.log('Collected: %d/%d', countGC, count);
assert.strictEqual(count, countGC);
process.exit(0);
}, 200);
}
if (countGC === todo) server.close();
}

0 comments on commit a3a6892

Please sign in to comment.