Skip to content

Commit e565f5f

Browse files
bnoordhuiskrydos
authored andcommitted
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: nodejs#11239 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Richard Lau <[email protected]>
1 parent 4d1b7bc commit e565f5f

5 files changed

+9
-56
lines changed

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

+2-13
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ function serverHandler(req, res) {
1010

1111
const http = require('http');
1212
const weak = require('weak');
13-
const assert = require('assert');
1413
const todo = 500;
1514
let done = 0;
1615
let count = 0;
@@ -28,7 +27,6 @@ function getall() {
2827
(function() {
2928
function cb(res) {
3029
done += 1;
31-
statusLater();
3230
}
3331

3432
const req = http.get({
@@ -51,20 +49,11 @@ function afterGC() {
5149
countGC++;
5250
}
5351

54-
let timer;
55-
function statusLater() {
56-
global.gc();
57-
if (timer) clearTimeout(timer);
58-
timer = setTimeout(status, 1);
59-
}
52+
setInterval(status, 100).unref();
6053

6154
function status() {
6255
global.gc();
6356
console.log('Done: %d/%d', done, todo);
6457
console.log('Collected: %d/%d', countGC, count);
65-
if (done === todo) {
66-
console.log('All should be collected now.');
67-
assert.strictEqual(count, countGC);
68-
process.exit(0);
69-
}
58+
if (countGC === todo) server.close();
7059
}

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

+2-13
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ function serverHandler(req, res) {
1212

1313
const http = require('http');
1414
const weak = require('weak');
15-
const assert = require('assert');
1615
const todo = 500;
1716
let done = 0;
1817
let count = 0;
@@ -31,7 +30,6 @@ function getall() {
3130
function cb(res) {
3231
res.resume();
3332
done += 1;
34-
statusLater();
3533
}
3634
function onerror(er) {
3735
throw er;
@@ -59,20 +57,11 @@ function afterGC() {
5957
countGC++;
6058
}
6159

62-
let timer;
63-
function statusLater() {
64-
global.gc();
65-
if (timer) clearTimeout(timer);
66-
timer = setTimeout(status, 1);
67-
}
60+
setInterval(status, 100).unref();
6861

6962
function status() {
7063
global.gc();
7164
console.log('Done: %d/%d', done, todo);
7265
console.log('Collected: %d/%d', countGC, count);
73-
if (done === todo) {
74-
console.log('All should be collected now.');
75-
assert.strictEqual(count, countGC);
76-
process.exit(0);
77-
}
66+
if (countGC === todo) server.close();
7867
}

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

+2-13
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ function serverHandler(req, res) {
1414

1515
const http = require('http');
1616
const weak = require('weak');
17-
const assert = require('assert');
1817
const todo = 550;
1918
let done = 0;
2019
let count = 0;
@@ -33,7 +32,6 @@ function getall() {
3332
function cb(res) {
3433
res.resume();
3534
done += 1;
36-
statusLater();
3735
}
3836

3937
const req = http.get({
@@ -60,20 +58,11 @@ function afterGC() {
6058
countGC++;
6159
}
6260

63-
let timer;
64-
function statusLater() {
65-
global.gc();
66-
if (timer) clearTimeout(timer);
67-
timer = setTimeout(status, 1);
68-
}
61+
setInterval(status, 100).unref();
6962

7063
function status() {
7164
global.gc();
7265
console.log('Done: %d/%d', done, todo);
7366
console.log('Collected: %d/%d', countGC, count);
74-
if (done === todo) {
75-
console.log('All should be collected now.');
76-
assert.strictEqual(count, countGC);
77-
process.exit(0);
78-
}
67+
if (countGC === todo) server.close();
7968
}

test/gc/test-http-client.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ function serverHandler(req, res) {
1010

1111
const http = require('http');
1212
const weak = require('weak');
13-
const assert = require('assert');
1413
const todo = 500;
1514
let done = 0;
1615
let count = 0;
@@ -54,15 +53,11 @@ function afterGC() {
5453
countGC++;
5554
}
5655

57-
setInterval(status, 1000).unref();
56+
setInterval(status, 100).unref();
5857

5958
function status() {
6059
global.gc();
6160
console.log('Done: %d/%d', done, todo);
6261
console.log('Collected: %d/%d', countGC, count);
63-
if (done === todo) {
64-
console.log('All should be collected now.');
65-
assert.strictEqual(count, countGC);
66-
process.exit(0);
67-
}
62+
if (countGC === todo) server.close();
6863
}

test/gc/test-net-timeout.js

+1-10
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,5 @@ function status() {
6262
global.gc();
6363
console.log('Done: %d/%d', done, todo);
6464
console.log('Collected: %d/%d', countGC, count);
65-
if (done === todo) {
66-
/* Give libuv some time to make close callbacks. */
67-
setTimeout(function() {
68-
global.gc();
69-
console.log('All should be collected now.');
70-
console.log('Collected: %d/%d', countGC, count);
71-
assert.strictEqual(count, countGC);
72-
process.exit(0);
73-
}, 200);
74-
}
65+
if (countGC === todo) server.close();
7566
}

0 commit comments

Comments
 (0)