Skip to content
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
6 changes: 6 additions & 0 deletions src/blueapi/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import time
from collections.abc import Iterable
from concurrent.futures import Future
from contextlib import suppress
from functools import cached_property
from itertools import chain
from pathlib import Path
Expand Down Expand Up @@ -675,6 +676,11 @@ def reload_environment(
"""
try:
status = self._rest.delete_environment()
# clear the cached plans/devices as they may have changed
with suppress(AttributeError):
del self.plans
with suppress(AttributeError):
del self.devices
except (
BlueskyRequestError,
ServiceUnavailableError,
Expand Down
19 changes: 19 additions & 0 deletions tests/unit_tests/client/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,25 @@ def test_reload_environment(
assert environment == NEW_ENV


def test_reload_environment_removes_caches(client: BlueapiClient, mock_rest: Mock):
mock_rest.get_environment.return_value = NEW_ENV

_ = client.plans, client.devices
_ = client.plans, client.devices

# rest calls only made once as plans/devices are cached
mock_rest.get_plans.assert_called_once()
mock_rest.get_devices.assert_called_once()
mock_rest.reset_mock()

client.reload_environment()
_ = client.plans, client.devices

# When environment is reloaded, caches are cleared so another call is required
mock_rest.get_plans.assert_called_once()
mock_rest.get_devices.assert_called_once()


@patch("blueapi.client.client.time.time")
@patch("blueapi.client.client.time.sleep")
def test_reload_environment_no_timeout(
Expand Down
Loading