From f8c2302a66a796deac6d06c41c591648fccbc0a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AC=91=E6=96=8C?= Date: Sun, 16 Jul 2017 15:00:08 +0800 Subject: [PATCH] test: use common.mustCall() instead of exit handle PR-URL: https://github.com/nodejs/node/pull/14262 Reviewed-By: Rich Trott Reviewed-By: Colin Ihrig Reviewed-By: Anna Henningsen Reviewed-By: Yuta Hiroto Reviewed-By: Gireesh Punathil Reviewed-By: James M Snell --- .../test-http-server-keep-alive-timeout.js | 18 +++------------ .../test-https-server-keep-alive-timeout.js | 22 +++++-------------- 2 files changed, 9 insertions(+), 31 deletions(-) diff --git a/test/parallel/test-http-server-keep-alive-timeout.js b/test/parallel/test-http-server-keep-alive-timeout.js index dace64e4d02559..767963fbdc2f38 100644 --- a/test/parallel/test-http-server-keep-alive-timeout.js +++ b/test/parallel/test-http-server-keep-alive-timeout.js @@ -1,7 +1,6 @@ 'use strict'; const common = require('../common'); -const assert = require('assert'); const http = require('http'); const net = require('net'); @@ -20,14 +19,9 @@ function run() { } test(function serverEndKeepAliveTimeoutWithPipeline(cb) { - let requestCount = 0; - process.on('exit', () => { - assert.strictEqual(requestCount, 3); - }); - const server = http.createServer((req, res) => { - requestCount++; + const server = http.createServer(common.mustCall((req, res) => { res.end(); - }); + }, 3)); server.setTimeout(500, common.mustCall((socket) => { // End this test and call `run()` for the next test (if any). socket.destroy(); @@ -49,13 +43,7 @@ test(function serverEndKeepAliveTimeoutWithPipeline(cb) { }); test(function serverNoEndKeepAliveTimeoutWithPipeline(cb) { - let requestCount = 0; - process.on('exit', () => { - assert.strictEqual(requestCount, 3); - }); - const server = http.createServer((req, res) => { - requestCount++; - }); + const server = http.createServer(common.mustCall(3)); server.setTimeout(500, common.mustCall((socket) => { // End this test and call `run()` for the next test (if any). socket.destroy(); diff --git a/test/parallel/test-https-server-keep-alive-timeout.js b/test/parallel/test-https-server-keep-alive-timeout.js index b302205e5e272f..ae6b4312684200 100644 --- a/test/parallel/test-https-server-keep-alive-timeout.js +++ b/test/parallel/test-https-server-keep-alive-timeout.js @@ -4,7 +4,6 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); -const assert = require('assert'); const https = require('https'); const tls = require('tls'); const fs = require('fs'); @@ -29,14 +28,11 @@ function run() { } test(function serverKeepAliveTimeoutWithPipeline(cb) { - let requestCount = 0; - process.on('exit', function() { - assert.strictEqual(requestCount, 3); - }); - const server = https.createServer(serverOptions, (req, res) => { - requestCount++; - res.end(); - }); + const server = https.createServer( + serverOptions, + common.mustCall((req, res) => { + res.end(); + }, 3)); server.setTimeout(500, common.mustCall((socket) => { // End this test and call `run()` for the next test (if any). socket.destroy(); @@ -59,13 +55,7 @@ test(function serverKeepAliveTimeoutWithPipeline(cb) { }); test(function serverNoEndKeepAliveTimeoutWithPipeline(cb) { - let requestCount = 0; - process.on('exit', () => { - assert.strictEqual(requestCount, 3); - }); - const server = https.createServer(serverOptions, (req, res) => { - requestCount++; - }); + const server = https.createServer(serverOptions, common.mustCall(3)); server.setTimeout(500, common.mustCall((socket) => { // End this test and call `run()` for the next test (if any). socket.destroy();