Browse Source

test: don't call process.exit() in gc tests

Rewrite the tests in test/gc so that they no longer call process.exit().
Instead they exit gracefully now.

PR-URL: https://github.com/nodejs/node/pull/11239
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
v6
Ben Noordhuis 8 years ago
parent
commit
da52fcdcf5
  1. 15
      test/gc/test-http-client-connaborted.js
  2. 15
      test/gc/test-http-client-onerror.js
  3. 15
      test/gc/test-http-client-timeout.js
  4. 9
      test/gc/test-http-client.js
  5. 11
      test/gc/test-net-timeout.js

15
test/gc/test-http-client-connaborted.js

@ -10,7 +10,6 @@ function serverHandler(req, res) {
const http = require('http'); const http = require('http');
const weak = require('weak'); const weak = require('weak');
const assert = require('assert');
const todo = 500; const todo = 500;
let done = 0; let done = 0;
let count = 0; let count = 0;
@ -28,7 +27,6 @@ function getall() {
(function() { (function() {
function cb(res) { function cb(res) {
done += 1; done += 1;
statusLater();
} }
const req = http.get({ const req = http.get({
@ -51,20 +49,11 @@ function afterGC() {
countGC++; countGC++;
} }
let timer; setInterval(status, 100).unref();
function statusLater() {
global.gc();
if (timer) clearTimeout(timer);
timer = setTimeout(status, 1);
}
function status() { function status() {
global.gc(); global.gc();
console.log('Done: %d/%d', done, todo); console.log('Done: %d/%d', done, todo);
console.log('Collected: %d/%d', countGC, count); console.log('Collected: %d/%d', countGC, count);
if (done === todo) { if (countGC === todo) server.close();
console.log('All should be collected now.');
assert.strictEqual(count, countGC);
process.exit(0);
}
} }

15
test/gc/test-http-client-onerror.js

@ -12,7 +12,6 @@ function serverHandler(req, res) {
const http = require('http'); const http = require('http');
const weak = require('weak'); const weak = require('weak');
const assert = require('assert');
const todo = 500; const todo = 500;
let done = 0; let done = 0;
let count = 0; let count = 0;
@ -31,7 +30,6 @@ function getall() {
function cb(res) { function cb(res) {
res.resume(); res.resume();
done += 1; done += 1;
statusLater();
} }
function onerror(er) { function onerror(er) {
throw er; throw er;
@ -59,20 +57,11 @@ function afterGC() {
countGC++; countGC++;
} }
let timer; setInterval(status, 100).unref();
function statusLater() {
global.gc();
if (timer) clearTimeout(timer);
timer = setTimeout(status, 1);
}
function status() { function status() {
global.gc(); global.gc();
console.log('Done: %d/%d', done, todo); console.log('Done: %d/%d', done, todo);
console.log('Collected: %d/%d', countGC, count); console.log('Collected: %d/%d', countGC, count);
if (done === todo) { if (countGC === todo) server.close();
console.log('All should be collected now.');
assert.strictEqual(count, countGC);
process.exit(0);
}
} }

15
test/gc/test-http-client-timeout.js

@ -14,7 +14,6 @@ function serverHandler(req, res) {
const http = require('http'); const http = require('http');
const weak = require('weak'); const weak = require('weak');
const assert = require('assert');
const todo = 550; const todo = 550;
let done = 0; let done = 0;
let count = 0; let count = 0;
@ -33,7 +32,6 @@ function getall() {
function cb(res) { function cb(res) {
res.resume(); res.resume();
done += 1; done += 1;
statusLater();
} }
const req = http.get({ const req = http.get({
@ -60,20 +58,11 @@ function afterGC() {
countGC++; countGC++;
} }
let timer; setInterval(status, 100).unref();
function statusLater() {
global.gc();
if (timer) clearTimeout(timer);
timer = setTimeout(status, 1);
}
function status() { function status() {
global.gc(); global.gc();
console.log('Done: %d/%d', done, todo); console.log('Done: %d/%d', done, todo);
console.log('Collected: %d/%d', countGC, count); console.log('Collected: %d/%d', countGC, count);
if (done === todo) { if (countGC === todo) server.close();
console.log('All should be collected now.');
assert.strictEqual(count, countGC);
process.exit(0);
}
} }

9
test/gc/test-http-client.js

@ -10,7 +10,6 @@ function serverHandler(req, res) {
const http = require('http'); const http = require('http');
const weak = require('weak'); const weak = require('weak');
const assert = require('assert');
const todo = 500; const todo = 500;
let done = 0; let done = 0;
let count = 0; let count = 0;
@ -54,15 +53,11 @@ function afterGC() {
countGC++; countGC++;
} }
setInterval(status, 1000).unref(); setInterval(status, 100).unref();
function status() { function status() {
global.gc(); global.gc();
console.log('Done: %d/%d', done, todo); console.log('Done: %d/%d', done, todo);
console.log('Collected: %d/%d', countGC, count); console.log('Collected: %d/%d', countGC, count);
if (done === todo) { if (countGC === todo) server.close();
console.log('All should be collected now.');
assert.strictEqual(count, countGC);
process.exit(0);
}
} }

11
test/gc/test-net-timeout.js

@ -62,14 +62,5 @@ function status() {
global.gc(); global.gc();
console.log('Done: %d/%d', done, todo); console.log('Done: %d/%d', done, todo);
console.log('Collected: %d/%d', countGC, count); console.log('Collected: %d/%d', countGC, count);
if (done === todo) { if (countGC === todo) server.close();
/* 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);
}
} }

Loading…
Cancel
Save