Skip to content

Commit c910187

Browse files
committed
Fix state test.
Fixes #211 Signed-off-by: Gil Bregman <gbregman@il.ibm.com>
1 parent 25640b8 commit c910187

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tests/test_state.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22
import time
33
import rados
4+
import threading
45
from control.state import LocalGatewayState, OmapGatewayState, GatewayStateHandler
56

67

@@ -106,9 +107,11 @@ def test_state_notify_update(config, ioctx, local_state, omap_state):
106107
"""Confirms use of OMAP watch/notify for updates."""
107108

108109
update_counter = 0
110+
notify_event = threading.Event() # Event to signal when notify is called
109111

110112
def _state_notify_update(update, is_add_req):
111113
nonlocal update_counter
114+
nonlocal notify_event
112115
update_counter += 1
113116
elapsed = time.time() - start
114117
assert elapsed < update_interval_sec
@@ -132,6 +135,7 @@ def _state_notify_update(update, is_add_req):
132135
assert is_add_req is False
133136
assert k == key
134137
assert update_counter < 5
138+
notify_event.set() # Signal that notify was called
135139

136140
version = 1
137141
update_interval_sec = 10
@@ -148,18 +152,30 @@ def _state_notify_update(update, is_add_req):
148152
add_key(ioctx, key, "add", version, omap_state.omap_name,
149153
omap_state.OMAP_VERSION_KEY)
150154
assert (ioctx.notify(omap_state.omap_name)) # Send notify signal
155+
# Wait for the notify to be triggered
156+
assert notify_event.wait(update_interval_sec - 0.5)
157+
notify_event.clear() # Reset the event for the next notification
158+
assert update_counter == 1
151159

152160
# Change namespace key and update version number
153161
version += 1
154162
add_key(ioctx, key, "changed", version, omap_state.omap_name,
155163
omap_state.OMAP_VERSION_KEY)
156164
assert (ioctx.notify(omap_state.omap_name)) # Send notify signal
165+
# Wait for the notify to be triggered
166+
assert notify_event.wait(update_interval_sec - 0.5)
167+
notify_event.clear() # Reset the event for the next notification
168+
assert update_counter == 3
157169

158170
# Remove namespace key and update version number
159171
version += 1
160172
remove_key(ioctx, key, version, omap_state.omap_name,
161173
omap_state.OMAP_VERSION_KEY)
162174
assert (ioctx.notify(omap_state.omap_name)) # Send notify signal
175+
# Wait for the notify to be triggered
176+
assert notify_event.wait(update_interval_sec - 0.5)
177+
notify_event.clear() # Reset the event for the next notification
178+
assert update_counter == 4
163179

164180
# any wait interval smaller than update_interval_sec = 10 should be good
165181
# to test notify capability

0 commit comments

Comments
 (0)