File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const common = require ( '../common' ) ;
4+ const assert = require ( 'assert' ) ;
5+ const net = require ( 'net' ) ;
6+
7+ const COUNT = 1000 + 1 ;
8+ let gotResponses = 0 ;
9+
10+ const response = Buffer . from ( 'HTTP/1.1 200 OK\r\n\r\n' ) ;
11+
12+ function execAndClose ( ) {
13+ process . stdout . write ( '.' ) ;
14+
15+ const chunks = [ ] ;
16+ const socket = net . connect ( common . PORT ) ;
17+
18+ socket . on ( 'end' , socket . end ) ;
19+ socket . on ( 'connect' , function ( ) {
20+ process . stdout . write ( 'c' ) ;
21+ } ) ;
22+ socket . on ( 'data' , function ( chunk ) {
23+ process . stdout . write ( 'd' ) ;
24+ chunks . push ( chunk ) ;
25+ } ) ;
26+ socket . on ( 'close' , function ( ) {
27+ assert . deepStrictEqual ( Buffer . concat ( chunks ) , response ) ;
28+
29+ if ( ++ gotResponses === COUNT ) {
30+ server . close ( ) ;
31+ } else {
32+ execAndClose ( ) ;
33+ }
34+ } ) ;
35+ }
36+
37+ const server = net . createServer ( function ( socket ) {
38+ socket . end ( response ) ;
39+ socket . resume ( ) ;
40+ } ) ;
41+
42+ server . listen ( common . PORT , common . mustCall ( execAndClose ) ) ;
You can’t perform that action at this time.
0 commit comments