import { P2P } from '../../src/index' ; import { wait } from '../utils/helpers' ; import { createNetwork , destroyNetwork , DEFAULT_CONNECTION_TIMEOUT } from '../utils/network_setup' ; describe ( 'Cleanup unresponsive peers' , ( ) => { let p2pNodeList = [ ] ; beforeEach ( async ( ) => { p2pNodeList = await createNetwork ( { networkSize : 4 } ) ; } ) ; afterEach ( async ( ) => { await destroyNetwork ( p2pNodeList ) ; } ) ; it ( 'should remove crashed nodes from network status of other nodes' , async ( ) => { const peerPortsbeforePeerCrash = p2pNodeList [ 2 ] . getConnectedPeers ( ) . map ( peerInfo => peerInfo . port ) . sort ( ) ; await p2pNodeList [ 0 ] . stop ( ) ; await p2pNodeList [ 1 ] . stop ( ) ; await wait ( DEFAULT_CONNECTION_TIMEOUT ) ; const peerPortsAfterPeerCrash = p2pNodeList [ 2 ] . getConnectedPeers ( ) . map ( peerInfo => peerInfo . port ) . sort ( ) ; const expectedPeerPortsAfterPeerCrash = peerPortsbeforePeerCrash . filter ( port => { return port !== p2pNodeList [ 0 ] . config . port && port !== p2pNodeList [ 1 ] . config . port ; } ) ; expect ( peerPortsAfterPeerCrash ) . toEqual ( expectedPeerPortsAfterPeerCrash ) ; } ) ; } ) ;