1- import time
2- import itertools
3-
41from hazelcast import HazelcastClient
52from hazelcast .core import Address
63from tests .base import HazelcastTestCase
74from hazelcast .config import ClientConfig , ClientProperties
8- from tests .util import configure_logging
5+ from tests .util import configure_logging , open_connection_to_address
96
107
118class HeartbeatTest (HazelcastTestCase ):
@@ -34,24 +31,6 @@ def tearDown(self):
3431
3532 def test_heartbeat_stopped (self ):
3633
37- def member_added_func (m ):
38- retry_count = itertools .count (3 , - 1 )
39-
40- def connection_callback (f ):
41- try :
42- conn = f .result ()
43- self .simulate_heartbeat_lost (self .client , Address (conn ._address [0 ], conn ._address [1 ]), 2 )
44- except :
45- if next (retry_count ) > 0 :
46- time .sleep (1 )
47- self .client .connection_manager .get_or_connect (m .address ).add_done_callback (connection_callback )
48- else :
49- self .fail ("Couldn't connect to address {}" .format (m .address ))
50-
51- self .client .connection_manager .get_or_connect (m .address ).add_done_callback (connection_callback )
52-
53- self .client .cluster .add_listener (member_added = member_added_func )
54-
5534 def connection_collector ():
5635 connections = []
5736
@@ -68,6 +47,9 @@ def collector(c):
6847 on_heartbeat_restored = heartbeat_restored_collector )
6948
7049 member2 = self .rc .startMember (self .cluster .id )
50+ addr = Address (member2 .host , member2 .port )
51+ open_connection_to_address (self .client , addr )
52+ self .simulate_heartbeat_lost (self .client , addr , 2 )
7153
7254 def assert_heartbeat_stopped_and_restored ():
7355 self .assertEqual (1 , len (heartbeat_stopped_collector .connections ))
0 commit comments