From 2db02d2d7cfb3d895c88086a396bfc55199e1444 Mon Sep 17 00:00:00 2001 From: Geoff Goodman Date: Fri, 15 Sep 2023 14:45:23 -0400 Subject: [PATCH] test: adhere more closely to test best practices --- .../test-pipe-abstract-socket-http.js | 88 +++++-------------- 1 file changed, 22 insertions(+), 66 deletions(-) diff --git a/test/parallel/test-pipe-abstract-socket-http.js b/test/parallel/test-pipe-abstract-socket-http.js index 6b7be4de36d822..6d3beb44d1e277 100644 --- a/test/parallel/test-pipe-abstract-socket-http.js +++ b/test/parallel/test-pipe-abstract-socket-http.js @@ -1,71 +1,27 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - 'use strict'; const common = require('../common'); const assert = require('assert'); const http = require('http'); -if (!common.isLinux) - common.skip(); - -const abstractSocket = '\0abstract'; - -let resStatus; - -const server = http.createServer((req, res) => { - assert.strictEqual(req.method, 'POST'); - - req.resume(); - - req.on('end', () => { - res.writeHead(200, { 'Content-Type': 'text/plain' }); - res.end(); - }); -}); -server.listen(abstractSocket); - -server.on('listening', () => { - makeRequest(); -}); - -function makeRequest() { - const req = http.request({ - path: '/', - method: 'POST', - socketPath: abstractSocket, - }); - - req.end(); - - req.on('response', (res) => { - resStatus = res.statusCode; - - res.resume(); - res.on('end', () => { - server.close(); - }); - }); -} - -process.on('exit', () => { - assert.strictEqual(resStatus, 200); -}); +if (!common.isLinux) common.skip(); + +const server = http.createServer( + common.mustCall((req, res) => { + res.end('ok'); + }) +); + +server.listen( + '\0abstract', + common.mustCall(() => { + http.get( + { + socketPath: server.address(), + }, + common.mustCall((res) => { + assert.strictEqual(res.statusCode, 200); + server.close(); + }) + ); + }) +);