From 179cdde693e0d8ccce8bbdeff77351abf23a158e Mon Sep 17 00:00:00 2001 From: Freddie Akeroyd Date: Fri, 24 Apr 2026 21:41:05 +0100 Subject: [PATCH] Wait for block to exist --- test_bluesky.py | 5 +++++ utilities/utilities.py | 16 +++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/test_bluesky.py b/test_bluesky.py index 38e61aa..d96010f 100644 --- a/test_bluesky.py +++ b/test_bluesky.py @@ -29,9 +29,12 @@ from ophyd_async.plan_stubs import ensure_connected from utilities.utilities import ( + assert_with_timeout, + check_block_exists, load_config_if_not_already_loaded, set_genie_python_raises_exceptions, setup_simulated_wiring_tables, + wait_for_iocs_to_be_up, ) matplotlib.use("qtagg") @@ -50,8 +53,10 @@ class TestBluesky(unittest.TestCase): def setUp(self) -> None: g.set_instrument(None) load_config_if_not_already_loaded("bluesky_sys_test") + wait_for_iocs_to_be_up(["SIMPLE", "ISISDAE_01"], 300) setup_simulated_wiring_tables() set_genie_python_raises_exceptions(True) + assert_with_timeout(lambda: self.assertTrue(check_block_exists("p3", True)), 60) g.cset("p3", P3_INIT_VALUE) g.cset("p5", P5_INIT_VALUE) set_bluesky_log_levels("DEBUG") diff --git a/utilities/utilities.py b/utilities/utilities.py index 3414ac4..afcdcf6 100644 --- a/utilities/utilities.py +++ b/utilities/utilities.py @@ -510,18 +510,24 @@ def wrapper(*args: P.args, **kwargs: P.kwargs) -> None: return decorator -def check_block_exists(block_name: str) -> bool: +def check_block_exists(block_name: str, check_pv: bool = False) -> bool: """ - Check that the given block name is in the current blocks. + Check that the given block name is in the current blockserver/configuration + blocks list. Optionally check if the PV for the block also currently exists Args: block_name (str): The name of the block to check for + check_pv (bool): Additionally check PV related to block exists Returns: - bool: true if block is in current blocks, false if not. + bool: true if block exists as per criteria, false if not. """ - blocks = g.get_blocks() - return block_name in blocks + block_in_list = block_name in g.get_blocks() + return ( + block_in_list and genie_api_setup.__api.block_exists(block_name) + if check_pv + else block_in_list + ) def retry_assert(retry_limit: int, func: Callable[[], None], retry_time: float = 1.0) -> None: