-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
test: import test-http-server-keep-alive-timeout #13448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,77 +1,122 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
| const assert = require('assert'); | ||
| const http = require('http'); | ||
| const net = require('net'); | ||
| module.exports.testServerKeepAliveTimeout = function(common, isHttps) { | ||
| let http; | ||
| let net; | ||
| let createOptions; | ||
| let serverOptions; | ||
| let createServer; | ||
|
|
||
| const tests = []; | ||
| if (isHttps) { | ||
|
||
| if (!common.hasCrypto) { | ||
| common.skip('missing crypto'); | ||
| return; | ||
| } | ||
|
|
||
| function test(fn) { | ||
| if (!tests.length) { | ||
| process.nextTick(run); | ||
| } | ||
| tests.push(fn); | ||
| } | ||
|
|
||
| function run() { | ||
| const fn = tests.shift(); | ||
| if (fn) fn(run); | ||
| } | ||
|
|
||
| test(function serverEndKeepAliveTimeoutWithPipeline(cb) { | ||
| let requestCount = 0; | ||
| process.on('exit', () => { | ||
| assert.strictEqual(requestCount, 3); | ||
| }); | ||
| const server = http.createServer((req, res) => { | ||
| requestCount++; | ||
| res.end(); | ||
| }); | ||
| server.setTimeout(500, common.mustCall((socket) => { | ||
| // End this test and call `run()` for the next test (if any). | ||
| socket.destroy(); | ||
| server.close(); | ||
| cb(); | ||
| })); | ||
| server.keepAliveTimeout = 50; | ||
| server.listen(0, common.mustCall(() => { | ||
| const options = { | ||
| port: server.address().port, | ||
| allowHalfOpen: true | ||
| http = require('https'); | ||
| net = require('tls'); | ||
|
|
||
| createOptions = function(server) { | ||
| return { | ||
| port: server.address().port, | ||
| allowHalfOpen: true, | ||
| rejectUnauthorized: false | ||
| }; | ||
| }; | ||
| const c = net.connect(options, () => { | ||
| c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n'); | ||
| c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n'); | ||
| c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n'); | ||
| }); | ||
| })); | ||
| }); | ||
|
|
||
| test(function serverNoEndKeepAliveTimeoutWithPipeline(cb) { | ||
| let requestCount = 0; | ||
| process.on('exit', () => { | ||
| assert.strictEqual(requestCount, 3); | ||
| }); | ||
| const server = http.createServer((req, res) => { | ||
| requestCount++; | ||
| }); | ||
| server.setTimeout(500, common.mustCall((socket) => { | ||
| // End this test and call `run()` for the next test (if any). | ||
| socket.destroy(); | ||
| server.close(); | ||
| cb(); | ||
| })); | ||
| server.keepAliveTimeout = 50; | ||
| server.listen(0, common.mustCall(() => { | ||
| const options = { | ||
| port: server.address().port, | ||
| allowHalfOpen: true | ||
| const fs = require('fs'); | ||
|
||
| serverOptions = { | ||
| key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), | ||
| cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') | ||
| }; | ||
| const c = net.connect(options, () => { | ||
| c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n'); | ||
| c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n'); | ||
| c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n'); | ||
|
|
||
| createServer = function(fn) { | ||
| return http.createServer(serverOptions, fn); | ||
| }; | ||
|
|
||
|
|
||
| } else { | ||
| http = require('http'); | ||
| net = require('net'); | ||
|
|
||
| createOptions = function(server) { | ||
| return { | ||
| port: server.address().port, | ||
|
||
| allowHalfOpen: true, | ||
| }; | ||
| }; | ||
|
|
||
| createServer = function(fn) { | ||
| return http.createServer(fn); | ||
| }; | ||
|
|
||
| } | ||
|
|
||
| const assert = require('assert'); | ||
| const tests = []; | ||
|
|
||
| function test(fn) { | ||
| if (!tests.length) { | ||
| process.nextTick(run); | ||
| } | ||
| tests.push(fn); | ||
| } | ||
|
|
||
| function run() { | ||
| const fn = tests.shift(); | ||
| if (fn) fn(run); | ||
| } | ||
|
|
||
| test(function serverKeepAliveTimeoutWithPipeline(cb) { | ||
| let requestCount = 0; | ||
| process.on('exit', function() { | ||
| assert.strictEqual(requestCount, 3); | ||
| }); | ||
| const server = createServer((req, res) => { | ||
| requestCount++; | ||
| res.end(); | ||
| }); | ||
| })); | ||
| }); | ||
| server.setTimeout(500, common.mustCall((socket) => { | ||
| // End this test and call `run()` for the next test (if any). | ||
| socket.destroy(); | ||
| server.close(); | ||
| cb(); | ||
| })); | ||
| server.keepAliveTimeout = 50; | ||
| server.listen(0, common.mustCall(() => { | ||
| const c = net.connect(createOptions(server), () => { | ||
| c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n'); | ||
| c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n'); | ||
| c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n'); | ||
| }); | ||
| })); | ||
| }); | ||
|
|
||
| test(function serverNoEndKeepAliveTimeoutWithPipeline(cb) { | ||
| let requestCount = 0; | ||
| process.on('exit', () => { | ||
| assert.strictEqual(requestCount, 3); | ||
| }); | ||
| const server = createServer((req, res) => { | ||
| requestCount++; | ||
| }); | ||
| server.setTimeout(500, common.mustCall((socket) => { | ||
| // End this test and call `run()` for the next test (if any). | ||
| socket.destroy(); | ||
| server.close(); | ||
| cb(); | ||
| })); | ||
| server.keepAliveTimeout = 50; | ||
| server.listen(0, common.mustCall(() => { | ||
| const c = net.connect(createOptions(server), () => { | ||
| c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n'); | ||
| c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n'); | ||
| c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n'); | ||
| }); | ||
| })); | ||
| }); | ||
| }; | ||
|
|
||
|
|
||
| const common = require('../common'); | ||
| module.exports.testServerKeepAliveTimeout(common, false); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,89 +1,5 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
| if (!common.hasCrypto) { | ||
| common.skip('missing crypto'); | ||
| return; | ||
| } | ||
| const assert = require('assert'); | ||
| const https = require('https'); | ||
| const tls = require('tls'); | ||
| const fs = require('fs'); | ||
|
|
||
| const tests = []; | ||
|
|
||
| const serverOptions = { | ||
| key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), | ||
| cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') | ||
| }; | ||
|
|
||
| function test(fn) { | ||
| if (!tests.length) { | ||
| process.nextTick(run); | ||
| } | ||
| tests.push(fn); | ||
| } | ||
|
|
||
| function run() { | ||
| const fn = tests.shift(); | ||
| if (fn) fn(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(); | ||
| }); | ||
| server.setTimeout(500, common.mustCall((socket) => { | ||
| // End this test and call `run()` for the next test (if any). | ||
| socket.destroy(); | ||
| server.close(); | ||
| cb(); | ||
| })); | ||
| server.keepAliveTimeout = 50; | ||
| server.listen(0, common.mustCall(() => { | ||
| const options = { | ||
| port: server.address().port, | ||
| allowHalfOpen: true, | ||
| rejectUnauthorized: false | ||
| }; | ||
| const c = tls.connect(options, () => { | ||
| c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n'); | ||
| c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n'); | ||
| c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n'); | ||
| }); | ||
| })); | ||
| }); | ||
|
|
||
| test(function serverNoEndKeepAliveTimeoutWithPipeline(cb) { | ||
| let requestCount = 0; | ||
| process.on('exit', () => { | ||
| assert.strictEqual(requestCount, 3); | ||
| }); | ||
| const server = https.createServer(serverOptions, (req, res) => { | ||
| requestCount++; | ||
| }); | ||
| server.setTimeout(500, common.mustCall((socket) => { | ||
| // End this test and call `run()` for the next test (if any). | ||
| socket.destroy(); | ||
| server.close(); | ||
| cb(); | ||
| })); | ||
| server.keepAliveTimeout = 50; | ||
| server.listen(0, common.mustCall(() => { | ||
| const options = { | ||
| port: server.address().port, | ||
| allowHalfOpen: true, | ||
| rejectUnauthorized: false | ||
| }; | ||
| const c = tls.connect(options, () => { | ||
| c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n'); | ||
| c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n'); | ||
| c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n'); | ||
| }); | ||
| })); | ||
| }); | ||
| const timeoutTest = require('./test-http-server-keep-alive-timeout'); | ||
|
||
| timeoutTest.testServerKeepAliveTimeout(common, true); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per https://github.com/nodejs/node/blob/master/doc/guides/writing-tests.md
put
const common = require('../common');as L2 then a blank line and then a commentThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a test file, not a library file. It shouldn't be exporting. -100 to exporting something to another test file from it.