@@ -2472,16 +2472,14 @@ describe('RPCClient', function(){
2472
2472
} ) ;
2473
2473
2474
2474
2475
- it ( 'should skip pinging client if other activity received with option deferPingsOnActivity' , async ( ) => {
2475
+ it ( 'should not auto-ping server if other activity received with option deferPingsOnActivity' , async ( ) => {
2476
2476
2477
2477
let pings = 0 ;
2478
2478
const { endpoint, close, server} = await createServer ( { } , {
2479
2479
withClient : async ( client ) => {
2480
- client . handle ( 'Echo' , async ( { params} ) => {
2481
- return params ;
2482
- } ) ;
2480
+ // send some rapid activity from the server
2483
2481
for ( let i = 0 ; i < 4 ; i ++ ) {
2484
- await cli . call ( 'Echo' , { } ) ;
2482
+ await client . call ( 'Echo' , { } ) ;
2485
2483
await setTimeout ( 25 ) ;
2486
2484
}
2487
2485
await client . close ( ) ;
@@ -2494,29 +2492,32 @@ describe('RPCClient', function(){
2494
2492
deferPingsOnActivity : true ,
2495
2493
pingIntervalMs : 40
2496
2494
} ) ;
2495
+ cli . handle ( 'Echo' , async ( { params} ) => {
2496
+ return params ;
2497
+ } ) ;
2497
2498
2499
+ // count how many times we ping the server
2498
2500
cli . on ( 'ping' , ( ) => { ++ pings ; } ) ;
2499
2501
2500
2502
try {
2501
2503
await cli . connect ( ) ;
2502
2504
await once ( cli , 'close' ) ;
2505
+ // we shouldn't have pinged, because of the activity sent from the server
2503
2506
assert . equal ( pings , 0 ) ;
2504
2507
} finally {
2505
2508
await cli . close ( ) ;
2506
2509
close ( ) ;
2507
2510
}
2508
2511
} ) ;
2509
2512
2510
- it ( 'should allow pinging client if other activity received without option deferPingsOnActivity' , async ( ) => {
2513
+ it ( 'should auto-ping server even if other activity received without option deferPingsOnActivity' , async ( ) => {
2511
2514
2512
2515
let pings = 0 ;
2513
2516
const { endpoint, close, server} = await createServer ( { } , {
2514
2517
withClient : async ( client ) => {
2515
- client . handle ( 'Echo' , async ( { params} ) => {
2516
- return params ;
2517
- } ) ;
2518
+ // send some rapid activity from the server
2518
2519
for ( let i = 0 ; i < 4 ; i ++ ) {
2519
- await cli . call ( 'Echo' , { } ) ;
2520
+ await client . call ( 'Echo' , { } ) ;
2520
2521
await setTimeout ( 25 ) ;
2521
2522
}
2522
2523
await client . close ( ) ;
@@ -2529,12 +2530,88 @@ describe('RPCClient', function(){
2529
2530
deferPingsOnActivity : false ,
2530
2531
pingIntervalMs : 40
2531
2532
} ) ;
2533
+ cli . handle ( 'Echo' , async ( { params} ) => {
2534
+ return params ;
2535
+ } ) ;
2536
+
2537
+ // count how many times we ping the server
2538
+ cli . on ( 'ping' , ( ) => { ++ pings ; } ) ;
2539
+
2540
+ try {
2541
+ await cli . connect ( ) ;
2542
+ await once ( cli , 'close' ) ;
2543
+ // we should have pinged multiple times, despite the activity sent from the server
2544
+ assert . ok ( pings > 0 ) ;
2545
+ } finally {
2546
+ await cli . close ( ) ;
2547
+ close ( ) ;
2548
+ }
2549
+ } ) ;
2550
+
2551
+
2552
+ it ( 'should not auto-ping server if ping received with option deferPingsOnActivity' , async ( ) => {
2553
+
2554
+ let pings = 0 ;
2555
+ const { endpoint, close, server} = await createServer ( {
2556
+ pingIntervalMs : 25 ,
2557
+ deferPingsOnActivity : false ,
2558
+ } , {
2559
+ withClient : async ( client ) => {
2560
+ // keep the client lingering long enough for the server to send several pings
2561
+ await setTimeout ( 110 ) ;
2562
+ await client . close ( ) ;
2563
+ }
2564
+ } ) ;
2565
+ const cli = new RPCClient ( {
2566
+ endpoint,
2567
+ identity : 'X' ,
2568
+ reconnect : false ,
2569
+ deferPingsOnActivity : true ,
2570
+ pingIntervalMs : 40
2571
+ } ) ;
2572
+
2573
+ // count how many times we ping the server
2574
+ cli . on ( 'ping' , ( ) => { ++ pings ; } ) ;
2575
+
2576
+ try {
2577
+ await cli . connect ( ) ;
2578
+ await once ( cli , 'close' ) ;
2579
+ // we shouldn't have pinged, because of the activity sent from the server
2580
+ assert . equal ( pings , 0 ) ;
2581
+ } finally {
2582
+ await cli . close ( ) ;
2583
+ close ( ) ;
2584
+ }
2585
+ } ) ;
2586
+
2587
+ it ( 'should auto-ping server even if ping received without option deferPingsOnActivity' , async ( ) => {
2588
+
2589
+ let pings = 0 ;
2590
+ const { endpoint, close, server} = await createServer ( {
2591
+ pingIntervalMs : 25 ,
2592
+ deferPingsOnActivity : false ,
2593
+ } , {
2594
+ withClient : async ( client ) => {
2595
+ // keep the client lingering long enough for the server to send several pings
2596
+ await setTimeout ( 110 ) ;
2597
+ await client . close ( ) ;
2598
+ }
2599
+ } ) ;
2600
+ const cli = new RPCClient ( {
2601
+ endpoint,
2602
+ identity : 'X' ,
2603
+ reconnect : false ,
2604
+ deferPingsOnActivity : false ,
2605
+ pingIntervalMs : 40
2606
+ } ) ;
2532
2607
2608
+ // count how many times we ping the server
2533
2609
cli . on ( 'ping' , ( ) => { ++ pings ; } ) ;
2534
2610
2535
2611
try {
2536
2612
await cli . connect ( ) ;
2537
2613
await once ( cli , 'close' ) ;
2614
+ // we should have pinged multiple times, despite the activity sent from the server
2538
2615
assert . ok ( pings > 0 ) ;
2539
2616
} finally {
2540
2617
await cli . close ( ) ;
0 commit comments