@@ -2568,7 +2568,7 @@ describe('Integration tests', function () {
2568
2568
} ) ;
2569
2569
2570
2570
describe ( 'Socket Ping/pong' , function ( ) {
2571
- describe ( 'When when pingTimeoutDisabled is not set' , function ( ) {
2571
+ describe ( 'When pingTimeoutDisabled is not set' , function ( ) {
2572
2572
beforeEach ( 'Launch server with ping options before start' , async function ( ) {
2573
2573
// Intentionally make pingInterval higher than pingTimeout, that
2574
2574
// way the client will never receive a ping or send back a pong.
@@ -2628,7 +2628,7 @@ describe('Integration tests', function () {
2628
2628
} ) ;
2629
2629
} ) ;
2630
2630
2631
- describe ( 'When when pingTimeoutDisabled is true' , function ( ) {
2631
+ describe ( 'When pingTimeoutDisabled is true' , function ( ) {
2632
2632
beforeEach ( 'Launch server with ping options before start' , async function ( ) {
2633
2633
// Intentionally make pingInterval higher than pingTimeout, that
2634
2634
// way the client will never receive a ping or send back a pong.
@@ -2687,12 +2687,67 @@ describe('Integration tests', function () {
2687
2687
assert . equal ( serverDisconnectionCode , null ) ;
2688
2688
} ) ;
2689
2689
} ) ;
2690
+
2691
+ describe ( 'When pingTimeout is greater than pingInterval' , function ( ) {
2692
+ beforeEach ( 'Launch server with ping options before start' , async function ( ) {
2693
+ // Intentionally make pingInterval higher than pingTimeout, that
2694
+ // way the client will never receive a ping or send back a pong.
2695
+ server = socketClusterServer . listen ( PORT_NUMBER , {
2696
+ authKey : serverOptions . authKey ,
2697
+ wsEngine : WS_ENGINE ,
2698
+ pingInterval : 400 ,
2699
+ pingTimeout : 1000
2700
+ } ) ;
2701
+ bindFailureHandlers ( server ) ;
2702
+
2703
+ await server . listener ( 'ready' ) . once ( ) ;
2704
+ } ) ;
2705
+
2706
+ it ( 'Should not disconnect socket if server receives a pong from client before timeout' , async function ( ) {
2707
+ client = socketClusterClient . create ( {
2708
+ hostname : clientOptions . hostname ,
2709
+ port : PORT_NUMBER
2710
+ } ) ;
2711
+
2712
+ let serverWarning = null ;
2713
+ ( async ( ) => {
2714
+ for await ( let { warning} of server . listener ( 'warning' ) ) {
2715
+ serverWarning = warning ;
2716
+ }
2717
+ } ) ( ) ;
2718
+
2719
+ let serverDisconnectionCode = null ;
2720
+ ( async ( ) => {
2721
+ for await ( let event of server . listener ( 'disconnection' ) ) {
2722
+ serverDisconnectionCode = event . code ;
2723
+ }
2724
+ } ) ( ) ;
2725
+
2726
+ let clientError = null ;
2727
+ ( async ( ) => {
2728
+ for await ( let { error} of client . listener ( 'error' ) ) {
2729
+ clientError = error ;
2730
+ }
2731
+ } ) ( ) ;
2732
+
2733
+ let clientDisconnectCode = null ;
2734
+ ( async ( ) => {
2735
+ for await ( let event of client . listener ( 'disconnect' ) ) {
2736
+ clientDisconnectCode = event . code ;
2737
+ }
2738
+ } ) ( ) ;
2739
+
2740
+ await wait ( 2000 ) ;
2741
+ assert . equal ( clientError , null ) ;
2742
+ assert . equal ( clientDisconnectCode , null ) ;
2743
+
2744
+ assert . equal ( serverWarning , null ) ;
2745
+ assert . equal ( serverDisconnectionCode , null ) ;
2746
+ } ) ;
2747
+ } ) ;
2690
2748
} ) ;
2691
2749
2692
2750
describe ( 'Middleware' , function ( ) {
2693
- let server ;
2694
- let client ;
2695
-
2696
2751
beforeEach ( 'Launch server without middleware before start' , async function ( ) {
2697
2752
server = socketClusterServer . listen ( PORT_NUMBER , {
2698
2753
authKey : serverOptions . authKey ,
@@ -2709,18 +2764,6 @@ describe('Integration tests', function () {
2709
2764
await server . listener ( 'ready' ) . once ( ) ;
2710
2765
} ) ;
2711
2766
2712
- afterEach ( 'Close server after each middleware test' , async function ( ) {
2713
- if ( client ) {
2714
- client . closeAllListeners ( ) ;
2715
- client . disconnect ( ) ;
2716
- }
2717
- if ( server ) {
2718
- server . closeAllListeners ( ) ;
2719
- server . httpServer . close ( ) ;
2720
- await server . close ( ) ;
2721
- }
2722
- } ) ;
2723
-
2724
2767
describe ( 'MIDDLEWARE_HANDSHAKE' , function ( ) {
2725
2768
describe ( 'HANDSHAKE_WS action' , function ( ) {
2726
2769
it ( 'Delaying handshake for one client should not affect other clients' , async function ( ) {
0 commit comments