@@ -41,21 +41,27 @@ var server = http.createServer(function(req, res) {
4141 requestBodyLength += data . length ;
4242 } ) ;
4343
44- var form = new IncomingForm ( { uploadDir : common . dir . tmp } ) ;
44+ req . on ( 'end' , function ( ) {
45+ // make sure total Content-Length is properly calculated
46+ assert . equal ( req . headers [ 'content-length' ] , requestBodyLength ) ;
47+ // successfully accepted request and it's good
48+ res . writeHead ( 200 ) ;
49+ } ) ;
4550
51+ var form = new IncomingForm ( { uploadDir : common . dir . tmp } ) ;
4652 form . parse ( req ) ;
4753
4854 form
4955 . on ( 'file' , function ( name , file ) {
50-
51- // make sure total Content-Length is properly calculated
52- assert . equal ( req . headers [ 'content-length' ] , requestBodyLength ) ;
5356 // make sure chunks are the same size
5457 assert . equal ( file . size , testSubjects [ name ] . readSize ) ;
58+ // clean up tested subject
59+ delete testSubjects [ name ] ;
5560 } )
56- . on ( 'end' , function ( ) {
57- res . writeHead ( 200 ) ;
58- res . end ( 'done' ) ;
61+ . on ( 'end' , function ( )
62+ {
63+ // done here
64+ res . end ( ) ;
5965 } ) ;
6066} ) ;
6167
@@ -88,10 +94,16 @@ server.listen(common.port, function() {
8894
8995 assert . strictEqual ( res . statusCode , 200 ) ;
9096
97+ // wait for server to finish
98+ res . on ( 'end' , function ( )
99+ {
100+ // check that all subjects were tested
101+ assert . strictEqual ( Object . keys ( testSubjects ) . length , 0 ) ;
102+ server . close ( ) ;
103+ } ) ;
104+
91105 // unstuck new streams
92106 res . resume ( ) ;
93-
94- server . close ( ) ;
95107 } ) ;
96108
97109} ) ;
0 commit comments