import { Global } from "../../lib/core/global" ; import { SocketHandler , SocketMessage } from "../../lib/core/socket-handler" ; import * as net from "net" ; import { Socket } from "net" ; import { KeepAlive } from "../../lib/client/keep-alive" ; import { Server } from "net" ; describe ( "KeepAlive" , function ( ) { describe ( "runs" , function ( ) { it ( "Does not get enough keep alive" , function ( done ) { let serverSocket = null ; let count = 0 ; let server = net . createServer ( function ( socket ) { serverSocket = new SocketHandler ( socket , function ( ) { count ++ ; console . log ( "Count: " + count ) ; if ( count < 10 ) { serverSocket . send ( new SocketMessage ( Global . KeepAliveMessage ) ) ; } else { } } ) ; } ) . listen ( 9000 ) ; let socket = net . connect ( 9000 , "localhost" , function ( ) { let handler = new SocketHandler ( socket , function ( ) { keepAlive . received ( ) ; } ) ; let keepAlive = new KeepAlive ( handler ) ; keepAlive . pingPeriod = 50 ; keepAlive . warningThreshold = 10 ; keepAlive . windowPeriod = 1000 ; let gotError = false ; keepAlive . start ( function ( ) { if ( gotError ) { return ; } gotError = true ; keepAlive . stop ( ) ; socket . end ( ) ; server . close ( function ( ) { done ( ) ; } ) ; } ) ; } ) ; } ) ; } ) ; } ) ;