Skip to content

Commit

Permalink
Pass time when test ended to DbusMonitor test
Browse files Browse the repository at this point in the history
Also, change name of check methods from tearDown to run_check.
"tearDown" has a special meaning for TestCase classes which these
methods do not have.

Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Feb 23, 2024
1 parent 0a5408b commit b76735e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
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

0 comments on commit b76735e

Please sign in to comment.