test: prefer server over srv

PR-URL: https://github.com/nodejs/node/pull/31224
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Andrew Hughes 2020-01-07 10:21:19 +00:00 committed by Rich Trott
parent 41dd175f6d
commit b0f67f2fc7
6 changed files with 20 additions and 20 deletions

View File

@ -28,7 +28,7 @@ require('../common');
const assert = require('assert'); const assert = require('assert');
const http = require('http'); const http = require('http');
const srv = http.createServer(function(req, res) { const server = http.createServer(function(req, res) {
assert.strictEqual(req.headers.accept, 'abc, def, ghijklmnopqrst'); assert.strictEqual(req.headers.accept, 'abc, def, ghijklmnopqrst');
assert.strictEqual(req.headers.host, 'foo'); assert.strictEqual(req.headers.host, 'foo');
assert.strictEqual(req.headers['www-authenticate'], 'foo, bar, baz'); assert.strictEqual(req.headers['www-authenticate'], 'foo, bar, baz');
@ -43,10 +43,10 @@ const srv = http.createServer(function(req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' }); res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('EOF'); res.end('EOF');
srv.close(); server.close();
}); });
srv.listen(0, function() { server.listen(0, function() {
http.get({ http.get({
host: 'localhost', host: 'localhost',
port: this.address().port, port: this.address().port,

View File

@ -69,7 +69,7 @@ const multipleForbidden = [
// 'Content-Length', // 'Content-Length',
]; ];
const srv = http.createServer(function(req, res) { const server = http.createServer(function(req, res) {
multipleForbidden.forEach(function(header) { multipleForbidden.forEach(function(header) {
assert.strictEqual(req.headers[header.toLowerCase()], 'foo', assert.strictEqual(req.headers[header.toLowerCase()], 'foo',
`header parsed incorrectly: ${header}`); `header parsed incorrectly: ${header}`);
@ -83,7 +83,7 @@ const srv = http.createServer(function(req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' }); res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('EOF'); res.end('EOF');
srv.close(); server.close();
}); });
function makeHeader(value) { function makeHeader(value) {
@ -98,7 +98,7 @@ const headers = []
.concat(multipleAllowed.map(makeHeader('bar'))) .concat(multipleAllowed.map(makeHeader('bar')))
.concat(multipleForbidden.map(makeHeader('bar'))); .concat(multipleForbidden.map(makeHeader('bar')));
srv.listen(0, function() { server.listen(0, function() {
http.get({ http.get({
host: 'localhost', host: 'localhost',
port: this.address().port, port: this.address().port,

View File

@ -31,7 +31,7 @@ const http = require('http');
const net = require('net'); const net = require('net');
// Create a TCP server // Create a TCP server
const srv = net.createServer(function(c) { const server = net.createServer(function(c) {
c.on('data', function(d) { c.on('data', function(d) {
c.write('HTTP/1.1 101\r\n'); c.write('HTTP/1.1 101\r\n');
c.write('hello: world\r\n'); c.write('hello: world\r\n');
@ -46,7 +46,7 @@ const srv = net.createServer(function(c) {
}); });
}); });
srv.listen(0, '127.0.0.1', common.mustCall(function() { server.listen(0, '127.0.0.1', common.mustCall(function() {
const options = { const options = {
port: this.address().port, port: this.address().port,
@ -82,7 +82,7 @@ srv.listen(0, '127.0.0.1', common.mustCall(function() {
req.on('close', common.mustCall(function() { req.on('close', common.mustCall(function() {
socket.end(); socket.end();
srv.close(); server.close();
})); }));
})); }));
})); }));

View File

@ -34,7 +34,7 @@ const Countdown = require('../common/countdown');
const expectedRecvData = 'nurtzo'; const expectedRecvData = 'nurtzo';
// Create a TCP server // Create a TCP server
const srv = net.createServer(function(c) { const server = net.createServer(function(c) {
c.on('data', function(d) { c.on('data', function(d) {
c.write('HTTP/1.1 101\r\n'); c.write('HTTP/1.1 101\r\n');
c.write('hello: world\r\n'); c.write('hello: world\r\n');
@ -49,7 +49,7 @@ const srv = net.createServer(function(c) {
}); });
}); });
srv.listen(0, '127.0.0.1', common.mustCall(function() { server.listen(0, '127.0.0.1', common.mustCall(function() {
const port = this.address().port; const port = this.address().port;
const headers = [ const headers = [
{ {
@ -63,7 +63,7 @@ srv.listen(0, '127.0.0.1', common.mustCall(function() {
['Origin', 'http://www.websocket.org'] ['Origin', 'http://www.websocket.org']
] ]
]; ];
const countdown = new Countdown(headers.length, () => srv.close()); const countdown = new Countdown(headers.length, () => server.close());
headers.forEach(function(h) { headers.forEach(function(h) {
const req = http.get({ const req = http.get({

View File

@ -37,14 +37,14 @@ function ready() {
} }
} }
const srv = net.createServer(function onConnection(conn) { const server = net.createServer(function onConnection(conn) {
conn.on('error', function(err) { conn.on('error', function(err) {
errs.push(err); errs.push(err);
if (errs.length > 1 && errs[0] === errs[1]) if (errs.length > 1 && errs[0] === errs[1])
assert.fail('Should not emit the same error twice'); assert.fail('Should not emit the same error twice');
}); });
conn.on('close', function() { conn.on('close', function() {
srv.unref(); server.unref();
}); });
serverSocket = conn; serverSocket = conn;
ready(); ready();

View File

@ -55,7 +55,7 @@ function randomPipePath() {
{ {
const handlePath = randomPipePath(); const handlePath = randomPipePath();
const srv = net.createServer() const server = net.createServer()
.listen({ .listen({
path: handlePath, path: handlePath,
readableAll: true, readableAll: true,
@ -66,24 +66,24 @@ function randomPipePath() {
assert.notStrictEqual(mode & fs.constants.S_IROTH, 0); assert.notStrictEqual(mode & fs.constants.S_IROTH, 0);
assert.notStrictEqual(mode & fs.constants.S_IWOTH, 0); assert.notStrictEqual(mode & fs.constants.S_IWOTH, 0);
} }
srv.close(); server.close();
})); }));
} }
// Test should emit "error" events when listening fails. // Test should emit "error" events when listening fails.
{ {
const handlePath = randomPipePath(); const handlePath = randomPipePath();
const srv1 = net.createServer().listen({ path: handlePath }, () => { const server1 = net.createServer().listen({ path: handlePath }, () => {
// As the handlePath is in use, binding to the same address again should // As the handlePath is in use, binding to the same address again should
// make the server emit an 'EADDRINUSE' error. // make the server emit an 'EADDRINUSE' error.
const srv2 = net.createServer() const server2 = net.createServer()
.listen({ .listen({
path: handlePath, path: handlePath,
writableAll: true, writableAll: true,
}, common.mustNotCall()); }, common.mustNotCall());
srv2.on('error', common.mustCall((err) => { server2.on('error', common.mustCall((err) => {
srv1.close(); server1.close();
assert.strictEqual(err.code, 'EADDRINUSE'); assert.strictEqual(err.code, 'EADDRINUSE');
assert(/^listen EADDRINUSE: address already in use/.test(err.message)); assert(/^listen EADDRINUSE: address already in use/.test(err.message));
})); }));