mirror of https://github.com/nodejs/node.git
test: replace console.log/error() with debuglog
PR-URL: https://github.com/nodejs/node/pull/32692 Fixes: https://github.com/nodejs/node/issues/32678 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Zeyu Yang <himself65@outlook.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
parent
4a6a5c3453
commit
a9da65699a
|
@ -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;
|
||||
|
@ -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');
|
||||
|
@ -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;
|
||||
|
@ -79,7 +80,7 @@ function next() {
|
|||
const dom = domain.create();
|
||||
dom.on('error', function(er) {
|
||||
clientCaught++;
|
||||
console.log('client error', er);
|
||||
debug('client error', er);
|
||||
req.socket.destroy();
|
||||
});
|
||||
|
||||
|
@ -87,9 +88,9 @@ function next() {
|
|||
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();
|
||||
}
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -111,5 +112,5 @@ function next() {
|
|||
process.on('exit', function() {
|
||||
assert.strictEqual(serverCaught, 2);
|
||||
assert.strictEqual(clientCaught, 2);
|
||||
console.log('ok');
|
||||
debug('ok');
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue