Skip to content

Commit 9192865

Browse files
committed
Fix heartbeat test that fails on Windows
Heartbeat test was failing on windows because while connecting to the second member that was created recently, member was throwing HazelcastInstanceNotActive exception during the client authentication process. With this fix, client will try to connect to the second member and if an exception occurs, it will sleep for a while and try again up to 3 times.
1 parent c372db7 commit 9192865

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

tests/heartbeat_test.py

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import time
2+
import itertools
3+
14
from hazelcast import HazelcastClient
25
from hazelcast.core import Address
36
from tests.base import HazelcastTestCase
@@ -32,45 +35,45 @@ def tearDown(self):
3235
def test_heartbeat_stopped(self):
3336

3437
def member_added_func(m):
38+
retry_count = itertools.count(3, -1)
39+
3540
def connection_callback(f):
36-
conn = f.result()
37-
self.simulate_heartbeat_lost(self.client, Address(conn._address[0], conn._address[1]), 2)
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))
3850

3951
self.client.connection_manager.get_or_connect(m.address).add_done_callback(connection_callback)
4052

4153
self.client.cluster.add_listener(member_added=member_added_func)
4254

43-
def heartbeat_stopped_collector():
44-
connections = []
45-
46-
def connection_collector(c):
47-
connections.append(c)
48-
49-
connection_collector.connections = connections
50-
return connection_collector
51-
52-
def heartbeat_restored_collector():
55+
def connection_collector():
5356
connections = []
5457

55-
def connection_collector(c):
58+
def collector(c):
5659
connections.append(c)
5760

58-
connection_collector.connections = connections
59-
return connection_collector
61+
collector.connections = connections
62+
return collector
6063

61-
stopped_collector = heartbeat_stopped_collector()
62-
restored_collector = heartbeat_restored_collector()
64+
heartbeat_stopped_collector = connection_collector()
65+
heartbeat_restored_collector = connection_collector()
6366

64-
self.client.heartbeat.add_listener(on_heartbeat_stopped=stopped_collector,
65-
on_heartbeat_restored=restored_collector)
67+
self.client.heartbeat.add_listener(on_heartbeat_stopped=heartbeat_stopped_collector,
68+
on_heartbeat_restored=heartbeat_restored_collector)
6669

6770
member2 = self.rc.startMember(self.cluster.id)
6871

6972
def assert_heartbeat_stopped_and_restored():
70-
self.assertEqual(1, len(stopped_collector.connections))
71-
self.assertEqual(1, len(restored_collector.connections))
72-
connection_stopped = stopped_collector.connections[0]
73-
connection_restored = restored_collector.connections[0]
73+
self.assertEqual(1, len(heartbeat_stopped_collector.connections))
74+
self.assertEqual(1, len(heartbeat_restored_collector.connections))
75+
connection_stopped = heartbeat_stopped_collector.connections[0]
76+
connection_restored = heartbeat_restored_collector.connections[0]
7477
self.assertEqual(connection_stopped._address, (member2.host, member2.port))
7578
self.assertEqual(connection_restored._address, (member2.host, member2.port))
7679

0 commit comments

Comments
 (0)