Browse Source

test: use common.mustCall() instead of exit handle

PR-URL: https://github.com/nodejs/node/pull/14262
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
v6
笑斌 8 years ago
committed by Rich Trott
parent
commit
2e864df6bf
  1. 18
      test/parallel/test-http-server-keep-alive-timeout.js
  2. 22
      test/parallel/test-https-server-keep-alive-timeout.js

18
test/parallel/test-http-server-keep-alive-timeout.js

@ -1,7 +1,6 @@
'use strict'; 'use strict';
const common = require('../common'); const common = require('../common');
const assert = require('assert');
const http = require('http'); const http = require('http');
const net = require('net'); const net = require('net');
@ -20,14 +19,9 @@ function run() {
} }
test(function serverEndKeepAliveTimeoutWithPipeline(cb) { test(function serverEndKeepAliveTimeoutWithPipeline(cb) {
let requestCount = 0; const server = http.createServer(common.mustCall((req, res) => {
process.on('exit', () => {
assert.strictEqual(requestCount, 3);
});
const server = http.createServer((req, res) => {
requestCount++;
res.end(); res.end();
}); }, 3));
server.setTimeout(500, common.mustCall((socket) => { server.setTimeout(500, common.mustCall((socket) => {
// End this test and call `run()` for the next test (if any). // End this test and call `run()` for the next test (if any).
socket.destroy(); socket.destroy();
@ -49,13 +43,7 @@ test(function serverEndKeepAliveTimeoutWithPipeline(cb) {
}); });
test(function serverNoEndKeepAliveTimeoutWithPipeline(cb) { test(function serverNoEndKeepAliveTimeoutWithPipeline(cb) {
let requestCount = 0; const server = http.createServer(common.mustCall(3));
process.on('exit', () => {
assert.strictEqual(requestCount, 3);
});
const server = http.createServer((req, res) => {
requestCount++;
});
server.setTimeout(500, common.mustCall((socket) => { server.setTimeout(500, common.mustCall((socket) => {
// End this test and call `run()` for the next test (if any). // End this test and call `run()` for the next test (if any).
socket.destroy(); socket.destroy();

22
test/parallel/test-https-server-keep-alive-timeout.js

@ -4,7 +4,6 @@ const common = require('../common');
if (!common.hasCrypto) if (!common.hasCrypto)
common.skip('missing crypto'); common.skip('missing crypto');
const assert = require('assert');
const https = require('https'); const https = require('https');
const tls = require('tls'); const tls = require('tls');
const fs = require('fs'); const fs = require('fs');
@ -29,14 +28,11 @@ function run() {
} }
test(function serverKeepAliveTimeoutWithPipeline(cb) { test(function serverKeepAliveTimeoutWithPipeline(cb) {
let requestCount = 0; const server = https.createServer(
process.on('exit', function() { serverOptions,
assert.strictEqual(requestCount, 3); common.mustCall((req, res) => {
}); res.end();
const server = https.createServer(serverOptions, (req, res) => { }, 3));
requestCount++;
res.end();
});
server.setTimeout(500, common.mustCall((socket) => { server.setTimeout(500, common.mustCall((socket) => {
// End this test and call `run()` for the next test (if any). // End this test and call `run()` for the next test (if any).
socket.destroy(); socket.destroy();
@ -59,13 +55,7 @@ test(function serverKeepAliveTimeoutWithPipeline(cb) {
}); });
test(function serverNoEndKeepAliveTimeoutWithPipeline(cb) { test(function serverNoEndKeepAliveTimeoutWithPipeline(cb) {
let requestCount = 0; const server = https.createServer(serverOptions, common.mustCall(3));
process.on('exit', () => {
assert.strictEqual(requestCount, 3);
});
const server = https.createServer(serverOptions, (req, res) => {
requestCount++;
});
server.setTimeout(500, common.mustCall((socket) => { server.setTimeout(500, common.mustCall((socket) => {
// End this test and call `run()` for the next test (if any). // End this test and call `run()` for the next test (if any).
socket.destroy(); socket.destroy();

Loading…
Cancel
Save