@@ -29,6 +29,9 @@ async function createServer({ expectedBodyLength }) {
2929 // Collect the raw protocol data and check it:
3030 socket . on ( 'data' , common . mustCall ( ( d ) => {
3131 socketData = Buffer . concat ( [ socketData , d ] ) ;
32+ } ) ) ;
33+
34+ socket . on ( 'end' , common . mustCall ( ( ) => {
3235 assert . strictEqual ( socketData . toString ( ) , 'upgrade head\npost-upgrade message' ) ;
3336 socket . end ( ) ;
3437 } ) ) ;
@@ -65,9 +68,9 @@ async function testUpgradeWithBody() {
6568
6669 // Send more data after connection is confirmed:
6770 conn . write ( '\npost-upgrade message' ) ;
71+ conn . end ( ) ;
6872
6973 await new Promise ( ( resolve ) => conn . on ( 'end' , resolve ) ) ;
70- conn . end ( ) ;
7174
7275 server . close ( ) ;
7376}
@@ -110,9 +113,9 @@ async function testUpgradeWithLargeBody() {
110113
111114 // Send more data after connection is confirmed:
112115 conn . write ( '\npost-upgrade message' ) ;
116+ conn . end ( ) ;
113117
114118 await new Promise ( ( resolve ) => conn . on ( 'end' , resolve ) ) ;
115- conn . end ( ) ;
116119
117120 server . close ( ) ;
118121}
@@ -145,9 +148,9 @@ async function testUpgradeWithUnreadBody() {
145148
146149 // Send more data after connection is confirmed:
147150 conn . write ( '\npost-upgrade message' ) ;
151+ conn . end ( ) ;
148152
149153 await new Promise ( ( resolve ) => conn . on ( 'end' , resolve ) ) ;
150- conn . end ( ) ;
151154
152155 server . close ( ) ;
153156}
@@ -192,9 +195,9 @@ async function testUpgradeWithUnreadLargeBody() {
192195
193196 // Send more data after connection is confirmed:
194197 conn . write ( '\npost-upgrade message' ) ;
198+ conn . end ( ) ;
195199
196200 await new Promise ( ( resolve ) => conn . on ( 'end' , resolve ) ) ;
197- conn . end ( ) ;
198201
199202 server . close ( ) ;
200203
0 commit comments