From 7603b4a693e67423eaa639aaa6e31fac8b8a04b8 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 25 Sep 2018 13:58:39 -0700 Subject: test: improve test-gc-http-client-connaborted test-gc-http-client-connaborted is resource-intensive. It times out a lot on CI. Move to sequential. PR-URL: https://github.com/nodejs/node/pull/23091 Fixes: https://github.com/metadata Reviewed-By: Anna Henningsen Reviewed-By: Gus Caplan Reviewed-By: Trivikram Kamat Reviewed-By: Sakthipriyan Vairamani --- test/sequential/test-gc-http-client-connaborted.js | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 test/sequential/test-gc-http-client-connaborted.js (limited to 'test/sequential') diff --git a/test/sequential/test-gc-http-client-connaborted.js b/test/sequential/test-gc-http-client-connaborted.js new file mode 100644 index 0000000000..c043c474a6 --- /dev/null +++ b/test/sequential/test-gc-http-client-connaborted.js @@ -0,0 +1,60 @@ +'use strict'; +// Flags: --expose-gc +// just like test-gc-http-client.js, +// but aborting every connection that comes in. + +require('../common'); +const onGC = require('../common/ongc'); + +function serverHandler(req, res) { + res.connection.destroy(); +} + +const http = require('http'); +const todo = 500; +let done = 0; +let count = 0; +let countGC = 0; + +console.log(`We should do ${todo} requests`); + +const server = http.createServer(serverHandler); +server.listen(0, getall); + +function getall() { + if (count >= todo) + return; + + (function() { + function cb(res) { + done += 1; + } + + const req = http.get({ + hostname: 'localhost', + pathname: '/', + port: server.address().port + }, cb).on('error', cb); + + count++; + onGC(req, { ongc }); + })(); + + setImmediate(getall); +} + +for (let i = 0; i < 10; i++) + getall(); + +function ongc() { + countGC++; +} + +setInterval(status, 100).unref(); + +function status() { + global.gc(); + console.log('Done: %d/%d', done, todo); + console.log('Collected: %d/%d', countGC, count); + if (countGC === todo) server.close(); +} -- cgit v1.2.3