Skip to content

Commit 51292cf

Browse files
jsouterGDYendell
andauthored
Fix softioc system test (#229)
* Prevent test failure in src docstring * fix startup of system softioc tests waiting for log messages * Tidy capturing of logs in system tests * Add some better exception handling * Ignore warnings in tests #230 --------- Co-authored-by: Gary Yendell <[email protected]>
1 parent b7ac911 commit 51292cf

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ addopts = """
8888
--tb=native -vv --doctest-modules --doctest-glob="*.md" --ignore-glob docs/snippets/*py --benchmark-sort=mean --benchmark-columns="mean, min, max, outliers, ops, rounds"
8989
"""
9090
# https://iscinumpy.gitlab.io/post/bound-version-constraints/#watch-for-warnings
91-
filterwarnings = "error"
91+
# https://github.com/DiamondLightSource/FastCS/issues/230
92+
# filterwarnings = "error"
9293
# Doctest python code in docs, python code in src docstrings, test functions in tests
9394
testpaths = "docs src tests"
9495

src/fastcs/launch.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,10 @@ def _stop_scan_tasks(self):
121121
if not task.done():
122122
try:
123123
task.cancel()
124-
except asyncio.CancelledError:
124+
except (asyncio.CancelledError, RuntimeError):
125125
pass
126+
except Exception as e:
127+
raise RuntimeError("Unhandled exception in stop scan tasks") from e
126128

127129
async def serve(self) -> None:
128130
coros = [self.serve_routines()]
@@ -159,6 +161,8 @@ async def serve(self) -> None:
159161
await asyncio.gather(*coros)
160162
except asyncio.CancelledError:
161163
pass
164+
except Exception as e:
165+
raise RuntimeError("Unhandled exception in serve") from e
162166

163167
async def _interactive_shell(self, context: dict[str, Any]):
164168
"""Spawn interactive shell in another thread and wait for it to complete."""

src/fastcs/tracer.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ class Tracer:
1919
Note: The global logger level must be set to ``TRACE`` for the messages to be logged
2020
2121
Example usage:
22-
>>> controller.ramp_rate.enable_tracing()
23-
>>> controller.ramp_rate.disable_tracing()
24-
>>> controller.connection.enable_tracing()
25-
>>> controller.connection.add_tracing_filter("query", "V?")
26-
>>> controller.connection.remove_tracing_filter("query", "V?")
27-
>>> controller.connection.disable_tracing()
22+
.. code-block:: python
23+
controller.ramp_rate.enable_tracing()
24+
controller.ramp_rate.disable_tracing()
25+
controller.connection.enable_tracing()
26+
controller.connection.add_tracing_filter("query", "V?")
27+
controller.connection.remove_tracing_filter("query", "V?")
28+
controller.connection.disable_tracing()
2829
2930
:param name: The name of the logger. Attached to log messages as ``logger_name``.
3031

tests/conftest.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from fastcs.attributes import AttrR, AttrRW, AttrW
2121
from fastcs.datatypes import Bool, Float, Int, String
2222
from fastcs.launch import build_controller_api
23+
from fastcs.logging import logger
2324
from fastcs.transport.tango.dsr import register_dev
2425
from tests.assertable_controller import MyTestAttributeIORef, MyTestController
2526
from tests.example_p4p_ioc import run as _run_p4p_ioc
@@ -86,6 +87,12 @@ def _run_ioc_as_subprocess(
8687
error_queue: multiprocessing.Queue,
8788
stdout_queue: multiprocessing.Queue,
8889
):
90+
# configure_logging(LogLevel.INFO)
91+
# we need to capture log messages from transport
92+
# logger = _logger.bind(logger_name="fastcs.transport.epics.ca.transport")
93+
logger.add(print) # forward log messages to stdout
94+
logger.enable("fastcs")
95+
8996
try:
9097
from pytest_cov.embed import cleanup_on_sigterm
9198
except ImportError:
@@ -127,7 +134,7 @@ def run_ioc_as_subprocess(
127134
start_time = time.monotonic()
128135
while True:
129136
try:
130-
if "Running FastCS IOC" in (
137+
if "Running IOC" in (
131138
stdout_queue.get(timeout=ioc_startup_timeout) # type: ignore
132139
):
133140
stdout_queue.get() # get the newline

0 commit comments

Comments
 (0)