Skip to content
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

test: replace console.log/error() with debuglog #32692

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions test/parallel/test-domain-http-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ require('../common');
const domain = require('domain');
const http = require('http');
const assert = require('assert');
const debug = require('util').debuglog('test');

const objects = { foo: 'bar', baz: {}, num: 42, arr: [1, 2, 3] };
objects.baz.asdf = objects;
Expand All @@ -39,7 +40,7 @@ const server = http.createServer(function(req, res) {

dom.on('error', function(er) {
serverCaught++;
console.log('horray! got a server error', er);
debug('horray! got a server error', er);
// Try to send a 500. If that fails, oh well.
res.writeHead(500, { 'content-type': 'text/plain' });
res.end(er.stack || er.message || 'Unknown error');
Expand All @@ -62,7 +63,7 @@ server.listen(0, next);

function next() {
const port = this.address().port;
console.log(`listening on localhost:${port}`);
debug(`listening on localhost:${port}`);

let requests = 0;
let responses = 0;
Expand All @@ -79,17 +80,17 @@ function next() {
const dom = domain.create();
dom.on('error', function(er) {
clientCaught++;
console.log('client error', er);
debug('client error', er);
req.socket.destroy();
});

const req = http.get({ host: 'localhost', port: port, path: p });
dom.add(req);
req.on('response', function(res) {
responses++;
console.error(`requests=${requests} responses=${responses}`);
debug(`requests=${requests} responses=${responses}`);
if (responses === requests) {
console.error('done, closing server');
debug('done, closing server');
// no more coming.
server.close();
}
Expand All @@ -100,9 +101,9 @@ function next() {
d += c;
});
res.on('end', function() {
console.error('trying to parse json', d);
debug('trying to parse json', d);
d = JSON.parse(d);
console.log('json!', d);
debug('json!', d);
});
});
}
Expand All @@ -111,5 +112,5 @@ function next() {
process.on('exit', function() {
assert.strictEqual(serverCaught, 2);
assert.strictEqual(clientCaught, 2);
console.log('ok');
debug('ok');
});