Skip to content

Commit

Permalink
Merge pull request #849 from gbregman/devel
Browse files Browse the repository at this point in the history
Fix state test
  • Loading branch information
gbregman authored Sep 3, 2024
2 parents 25640b8 + c910187 commit 34c77a2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/test_state.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
import time
import rados
import threading
from control.state import LocalGatewayState, OmapGatewayState, GatewayStateHandler


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

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

def _state_notify_update(update, is_add_req):
nonlocal update_counter
nonlocal notify_event
update_counter += 1
elapsed = time.time() - start
assert elapsed < update_interval_sec
Expand All @@ -132,6 +135,7 @@ def _state_notify_update(update, is_add_req):
assert is_add_req is False
assert k == key
assert update_counter < 5
notify_event.set() # Signal that notify was called

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

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

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

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

0 comments on commit 34c77a2

Please sign in to comment.