Skip to content

Commit

Permalink
test: replace console.log/error() with debuglog
Browse files Browse the repository at this point in the history
PR-URL: #32692
Fixes: #32678
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Zeyu Yang <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
  • Loading branch information
daemon1024 authored and BridgeAR committed Apr 28, 2020
1 parent 740f864 commit 4baf41f
Showing 1 changed file with 9 additions and 8 deletions.
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');
});

0 comments on commit 4baf41f

Please sign in to comment.