#NEWLINE# def test_idle_heartbeat( self ) : #NEWLINE# #INDENT# interval = 2 #NEWLINE# cluster = Cluster ( protocol_version = PROTOCOL_VERSION , idle_heartbeat_interval = interval ) #NEWLINE# if ( PROTOCOL_VERSION < 3 ) : #NEWLINE# #INDENT# cluster . set_core_connections_per_host ( HostDistance . LOCAL , 1 ) #NEWLINE# #UNINDENT# session = cluster . connect ( ) #NEWLINE# connection_request_ids = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for h in cluster . get_connection_holders ( ) : #NEWLINE# #INDENT# for c in h . get_connections ( ) : #NEWLINE# #INDENT# self . assertFalse ( c . is_idle ) #NEWLINE# with c . lock : #NEWLINE# #INDENT# connection_request_ids [ id ( c ) ] = deque ( c . request_ids ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# time . sleep ( ( ( 2 * interval ) + ( interval / 2 ) ) ) #NEWLINE# connections = [ c for holders in cluster . get_connection_holders ( ) for c in holders . get_connections ( ) ] #NEWLINE# for c in connections : #NEWLINE# #INDENT# expected_ids = connection_request_ids [ id ( c ) ] #NEWLINE# expected_ids . rotate ( ( - 1 ) ) #NEWLINE# with c . lock : #NEWLINE# #INDENT# self . assertListEqual ( list ( c . request_ids ) , list ( expected_ids ) ) #NEWLINE# #UNINDENT# #UNINDENT# self . assertTrue ( all ( ( c . is_idle for c in connections ) ) ) #NEWLINE# statements_and_params = ( [ ( 'SELECT release_version FROM system.local' , ( ) ) ] * len ( cluster . metadata . all_hosts ( ) ) ) #NEWLINE# results = execute_concurrent ( session , statements_and_params ) #NEWLINE# for ( success , result ) in results : #NEWLINE# #INDENT# self . assertTrue ( success ) #NEWLINE# #UNINDENT# self . assertFalse ( any ( ( ( c . is_idle if ( not c . is_control_connection ) else False ) for c in connections ) ) ) #NEWLINE# holders = cluster . get_connection_holders ( ) #NEWLINE# self . assertIn ( cluster . control_connection , holders ) #NEWLINE# self . assertEqual ( len ( holders ) , ( len ( cluster . metadata . all_hosts ( ) ) + 1 ) ) #NEWLINE# session2 = cluster . connect ( ) #NEWLINE# holders = cluster . get_connection_holders ( ) #NEWLINE# self . assertIn ( cluster . control_connection , holders ) #NEWLINE# self . assertEqual ( len ( holders ) , ( ( 2 * len ( cluster . metadata . all_hosts ( ) ) ) + 1 ) ) #NEWLINE# cluster . _idle_heartbeat . stop ( ) #NEWLINE# cluster . _idle_heartbeat . join ( ) #NEWLINE# assert_quiescent_pool_state ( self , cluster ) #NEWLINE# cluster . shutdown ( )