@@ -24,6 +24,9 @@ const common = require('../common');
2424if ( ! common . hasCrypto )
2525 common . skip ( 'missing crypto' ) ;
2626
27+ // This test ensures that the data received over tls-server after pause
28+ // is same as what it was sent
29+
2730const assert = require ( 'assert' ) ;
2831const tls = require ( 'tls' ) ;
2932const fixtures = require ( '../common/fixtures' ) ;
@@ -37,24 +40,23 @@ const bufSize = 1024 * 1024;
3740let sent = 0 ;
3841let received = 0 ;
3942
40- const server = tls . Server ( options , function ( socket ) {
43+ const server = tls . Server ( options , common . mustCall ( ( socket ) => {
4144 socket . pipe ( socket ) ;
42- socket . on ( 'data' , function ( c ) {
45+ socket . on ( 'data' , ( c ) => {
4346 console . error ( 'data' , c . length ) ;
4447 } ) ;
45- } ) ;
48+ } ) ) ;
4649
47- server . listen ( 0 , function ( ) {
50+ server . listen ( 0 , common . mustCall ( ( ) => {
4851 let resumed = false ;
4952 const client = tls . connect ( {
50- port : this . address ( ) . port ,
53+ port : server . address ( ) . port ,
5154 rejectUnauthorized : false
52- } , function ( ) {
55+ } , common . mustCall ( ( ) => {
5356 console . error ( 'connected' ) ;
5457 client . pause ( ) ;
5558 console . error ( 'paused' ) ;
56- send ( ) ;
57- function send ( ) {
59+ const send = ( ( ) => {
5860 console . error ( 'sending' ) ;
5961 const ret = client . write ( Buffer . allocUnsafe ( bufSize ) ) ;
6062 console . error ( `write => ${ ret } ` ) ;
@@ -69,9 +71,9 @@ server.listen(0, function() {
6971 resumed = true ;
7072 client . resume ( ) ;
7173 console . error ( 'resumed' , client ) ;
72- }
73- } ) ;
74- client . on ( 'data' , function ( data ) {
74+ } ) ( ) ;
75+ } ) ) ;
76+ client . on ( 'data' , ( data ) => {
7577 console . error ( 'data' ) ;
7678 assert . ok ( resumed ) ;
7779 received += data . length ;
@@ -83,8 +85,8 @@ server.listen(0, function() {
8385 server . close ( ) ;
8486 }
8587 } ) ;
86- } ) ;
88+ } ) ) ;
8789
88- process . on ( 'exit' , function ( ) {
90+ process . on ( 'exit' , ( ) => {
8991 assert . strictEqual ( sent , received ) ;
9092} ) ;
0 commit comments