1
1
import pytest
2
2
import time
3
3
import rados
4
+ import threading
4
5
from control .state import LocalGatewayState , OmapGatewayState , GatewayStateHandler
5
6
6
7
@@ -106,9 +107,11 @@ def test_state_notify_update(config, ioctx, local_state, omap_state):
106
107
"""Confirms use of OMAP watch/notify for updates."""
107
108
108
109
update_counter = 0
110
+ notify_event = threading .Event () # Event to signal when notify is called
109
111
110
112
def _state_notify_update (update , is_add_req ):
111
113
nonlocal update_counter
114
+ nonlocal notify_event
112
115
update_counter += 1
113
116
elapsed = time .time () - start
114
117
assert elapsed < update_interval_sec
@@ -132,6 +135,7 @@ def _state_notify_update(update, is_add_req):
132
135
assert is_add_req is False
133
136
assert k == key
134
137
assert update_counter < 5
138
+ notify_event .set () # Signal that notify was called
135
139
136
140
version = 1
137
141
update_interval_sec = 10
@@ -148,18 +152,30 @@ def _state_notify_update(update, is_add_req):
148
152
add_key (ioctx , key , "add" , version , omap_state .omap_name ,
149
153
omap_state .OMAP_VERSION_KEY )
150
154
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
151
159
152
160
# Change namespace key and update version number
153
161
version += 1
154
162
add_key (ioctx , key , "changed" , version , omap_state .omap_name ,
155
163
omap_state .OMAP_VERSION_KEY )
156
164
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
157
169
158
170
# Remove namespace key and update version number
159
171
version += 1
160
172
remove_key (ioctx , key , version , omap_state .omap_name ,
161
173
omap_state .OMAP_VERSION_KEY )
162
174
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
163
179
164
180
# any wait interval smaller than update_interval_sec = 10 should be good
165
181
# to test notify capability
0 commit comments