Skip to content

Commit

Permalink
test: adhere more closely to test best practices
Browse files Browse the repository at this point in the history
  • Loading branch information
ggoodman committed Sep 15, 2023
1 parent 3bddba0 commit 2db02d2
Showing 1 changed file with 22 additions and 66 deletions.
88 changes: 22 additions & 66 deletions test/parallel/test-pipe-abstract-socket-http.js
Original file line number Diff line number Diff line change
@@ -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();
})
);
})
);

0 comments on commit 2db02d2

Please sign in to comment.