@@ -24,6 +24,7 @@ require('../common');
24
24
const domain = require ( 'domain' ) ;
25
25
const http = require ( 'http' ) ;
26
26
const assert = require ( 'assert' ) ;
27
+ const debug = require ( 'util' ) . debuglog ( 'test' ) ;
27
28
28
29
const objects = { foo : 'bar' , baz : { } , num : 42 , arr : [ 1 , 2 , 3 ] } ;
29
30
objects . baz . asdf = objects ;
@@ -39,7 +40,7 @@ const server = http.createServer(function(req, res) {
39
40
40
41
dom . on ( 'error' , function ( er ) {
41
42
serverCaught ++ ;
42
- console . log ( 'horray! got a server error' , er ) ;
43
+ debug ( 'horray! got a server error' , er ) ;
43
44
// Try to send a 500. If that fails, oh well.
44
45
res . writeHead ( 500 , { 'content-type' : 'text/plain' } ) ;
45
46
res . end ( er . stack || er . message || 'Unknown error' ) ;
@@ -62,7 +63,7 @@ server.listen(0, next);
62
63
63
64
function next ( ) {
64
65
const port = this . address ( ) . port ;
65
- console . log ( `listening on localhost:${ port } ` ) ;
66
+ debug ( `listening on localhost:${ port } ` ) ;
66
67
67
68
let requests = 0 ;
68
69
let responses = 0 ;
@@ -79,17 +80,17 @@ function next() {
79
80
const dom = domain . create ( ) ;
80
81
dom . on ( 'error' , function ( er ) {
81
82
clientCaught ++ ;
82
- console . log ( 'client error' , er ) ;
83
+ debug ( 'client error' , er ) ;
83
84
req . socket . destroy ( ) ;
84
85
} ) ;
85
86
86
87
const req = http . get ( { host : 'localhost' , port : port , path : p } ) ;
87
88
dom . add ( req ) ;
88
89
req . on ( 'response' , function ( res ) {
89
90
responses ++ ;
90
- console . error ( `requests=${ requests } responses=${ responses } ` ) ;
91
+ debug ( `requests=${ requests } responses=${ responses } ` ) ;
91
92
if ( responses === requests ) {
92
- console . error ( 'done, closing server' ) ;
93
+ debug ( 'done, closing server' ) ;
93
94
// no more coming.
94
95
server . close ( ) ;
95
96
}
@@ -100,9 +101,9 @@ function next() {
100
101
d += c ;
101
102
} ) ;
102
103
res . on ( 'end' , function ( ) {
103
- console . error ( 'trying to parse json' , d ) ;
104
+ debug ( 'trying to parse json' , d ) ;
104
105
d = JSON . parse ( d ) ;
105
- console . log ( 'json!' , d ) ;
106
+ debug ( 'json!' , d ) ;
106
107
} ) ;
107
108
} ) ;
108
109
}
@@ -111,5 +112,5 @@ function next() {
111
112
process . on ( 'exit' , function ( ) {
112
113
assert . strictEqual ( serverCaught , 2 ) ;
113
114
assert . strictEqual ( clientCaught , 2 ) ;
114
- console . log ( 'ok' ) ;
115
+ debug ( 'ok' ) ;
115
116
} ) ;
0 commit comments