Skip to content

Commit ce5ec71

Browse files
authored
Fix remove_distributed_object_listener test (#261)
In the test, we were creating a map, and then immediately remove the listener. This works most of the time, but sometimes, event messages may arrive later, after we got a response from the get_map request. If we remove the listener after the get_map response, but before the late event, we will miss the event. Test is modified to wait for the created event, then removing the listener, then sleeping for a while and checking that there are no further events.
1 parent 37ec162 commit ce5ec71

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

tests/proxy/distributed_objects_test.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import time
2+
13
import hazelcast
24
from hazelcast.core import DistributedObjectEventType
35

@@ -99,16 +101,21 @@ def test_remove_distributed_object_listener(self):
99101
reg_id = self.client.add_distributed_object_listener(listener_func=collector).result()
100102
m = self.client.get_map("test-map")
101103

102-
response = self.client.remove_distributed_object_listener(reg_id).result()
103-
self.assertTrue(response)
104-
m.destroy()
105-
106-
# only map creation should be notified
107104
def assert_event():
108105
self.assertEqual(1, len(collector.events))
109106
event = collector.events[0]
110107
self.assertDistributedObjectEvent(event, "test-map", MAP_SERVICE, DistributedObjectEventType.CREATED)
108+
111109
self.assertTrueEventually(assert_event)
112110

111+
response = self.client.remove_distributed_object_listener(reg_id).result()
112+
self.assertTrue(response)
113+
m.destroy()
114+
115+
time.sleep(1)
116+
117+
# We should only receive the map created event
118+
assert_event()
119+
113120
def test_remove_invalid_distributed_object_listener(self):
114121
self.assertFalse(self.client.remove_distributed_object_listener("invalid-reg-id").result())

0 commit comments

Comments
 (0)