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

Pass time when test ended to DbusMonitor test #242

Merged
merged 1 commit into from
Feb 26, 2024
Merged
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
9 changes: 6 additions & 3 deletions stratisd_cert.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import json
import os
import sys
import time
import unittest
from tempfile import NamedTemporaryFile

Expand Down Expand Up @@ -219,11 +220,13 @@ def tearDown(self):

:return: None
"""
SysfsMonitor.tearDown(self)
stop_time = time.monotonic_ns()

SymlinkMonitor.tearDown(self)
SysfsMonitor.run_check(self)

DbusMonitor.tearDown(self)
SymlinkMonitor.run_check(self)

DbusMonitor.run_check(self, stop_time)

def _unittest_set_property(
self, object_path, param_iface, dbus_param, dbus_value, exception_name
Expand Down
32 changes: 27 additions & 5 deletions testlib/infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,29 @@ def setUp(self):
exec_command(["udevadm", "settle"])


def sleep_time(stop_time, wait_time):
"""
Calculate the time to sleep required so that the check commences
only after wait_time seconds have passed since the test ended.

:param int stop_time: time test was completed in nanoseconds
:param int wait_time: time to wait after test ends in seconds
:returns: time to sleep so that check does not commence early, seconds
"""
time_since_test_sec = (time.monotonic_ns() - stop_time) // 10**9

return (wait_time - time_since_test_sec) if (wait_time > time_since_test_sec) else 0


class SysfsMonitor(unittest.TestCase):
"""
Manage verification of sysfs files for devices.
"""

def tearDown(self):
def run_check(self):
"""
Run the check.
"""
if SysfsMonitor.verify_sysfs: # pylint: disable=no-member
dev_mapper = "/dev/mapper"
dm_devices = {
Expand Down Expand Up @@ -210,7 +227,10 @@ class SymlinkMonitor(unittest.TestCase):
Manage verification of device symlinks.
"""

def tearDown(self):
def run_check(self):
"""
Run the check.
"""
if SymlinkMonitor.verify_devices: # pylint: disable=no-member
try:
disallowed_symlinks = []
Expand Down Expand Up @@ -258,17 +278,19 @@ def setUp(self):
except FileNotFoundError as err:
raise RuntimeError("monitor_dbus_signals script not found.") from err

def tearDown(self):
def run_check(self, stop_time):
"""
Stop the D-Bus monitor script and check the results.

:param int stop_time: the time the test completed
"""
trace = getattr(self, "trace", None)
if trace is not None:
# A sixteen second sleep will make it virtually certain that
# A sixteen second wait will make it virtually certain that
# stratisd has a chance to do one of its 10 second timer passes on
# pools and filesystems _and_ that the D-Bus task has at least one
# second to send out any resulting signals.
time.sleep(16)
time.sleep(sleep_time(stop_time, 16))
self.trace.send_signal(signal.SIGINT)
(stdoutdata, stderrdata) = self.trace.communicate()
msg = stdoutdata.decode("utf-8")
Expand Down