Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: automated testing w/ github actions and state update component tests #109

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/test-components.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Runs unit-style tests when a PR is opened/reopened/updated on the devel branch

name: Test components
on:
pull_request:
branches:
- devel

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Python 3.9
uses: actions/setup-python@v1
with:
python-version: 3.9

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[test]

- name: Run component tests with pytest
run: pytest tests/component
2 changes: 2 additions & 0 deletions control/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def __exit__(self, exc_type, exc_value, traceback):
if exc_type is not None:
self.logger.exception("GatewayServer exception occurred:")

self.gateway_state.stop_event.set() # Stop updates

if self.spdk_process is not None:
self._stop_spdk()

Expand Down
18 changes: 11 additions & 7 deletions control/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ class GatewayStateHandler:
update_interval: Interval to periodically poll for updates
update_timer: Timer to check for gateway state updates
use_notify: Flag to indicate use of OMAP watch/notify
notify_event: Event to trigger immediate update
stop_event: Event to stop updates
"""

def __init__(self, config, local, omap, gateway_rpc_caller):
Expand All @@ -335,6 +337,8 @@ def __init__(self, config, local, omap, gateway_rpc_caller):
self.update_interval = 1
self.use_notify = self.config.getboolean("gateway",
"state_update_notify")
self.notify_event = threading.Event()
self.stop_event = threading.Event()

def add_bdev(self, bdev_name: str, val: str):
"""Adds a bdev to the state data stores."""
Expand Down Expand Up @@ -399,27 +403,27 @@ def delete_state(self):

def start_update(self):
"""Initiates periodic polling and watch/notify for updates."""
notify_event = threading.Event()
if self.use_notify:
# Register a watch on omap state
self.omap.register_watch(notify_event)
self.omap.register_watch(self.notify_event)

# Start polling for state updates
if self.update_timer is None:
self.update_timer = threading.Thread(target=self._update_caller,
daemon=True,
args=(notify_event,))
daemon=True)
self.update_timer.start()
else:
self.logger.info("Update timer already set.")

def _update_caller(self, notify_event):
def _update_caller(self):
"""Periodically calls for update."""
while True:
update_time = time.time() + self.update_interval
self.update()
notify_event.wait(max(update_time - time.time(), 0))
notify_event.clear()
self.notify_event.wait(max(update_time - time.time(), 0))
self.notify_event.clear()
if self.stop_event.is_set():
break

def update(self):
"""Checks for updated omap state and initiates local update."""
Expand Down
File renamed without changes.
Loading
Loading