Skip to content

Commit bdebc72

Browse files
authored
Fix apple2 timing out (#1709)
* fixes timeout * fixes timeout_for_LA too * fixes timeout_for_pol too * lint fix * ruff fix * add test to stop it from happening again * add linear arbitrary test
1 parent e2be4db commit bdebc72

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

src/dodal/devices/apple2_undulator.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
T = TypeVar("T")
3030

3131
DEFAULT_MOTOR_MIN_TIMEOUT = 10
32+
MAXIMUM_MOVE_TIME = 550 # There is no useful movements take longer than this.
3233

3334

3435
class UndulatorGateStatus(StrictEnum):
@@ -548,7 +549,7 @@ async def _set_pol(
548549
) -> None:
549550
# This changes the pol setpoint and then changes polarisation via set energy.
550551
self._polarisation_setpoint_set(value)
551-
await self.energy.set(await self.energy.get_value())
552+
await self.energy.set(await self.energy.get_value(), timeout=MAXIMUM_MOVE_TIME)
552553

553554
def _read_pol(
554555
self,
@@ -728,7 +729,7 @@ def __init__(self, id_controller: Apple2Controller, name: str = "") -> None:
728729

729730
@AsyncStatus.wrap
730731
async def set(self, energy: float) -> None:
731-
await self.energy().set(energy)
732+
await self.energy().set(energy, timeout=MAXIMUM_MOVE_TIME)
732733

733734

734735
class InsertionDevicePolarisation(StandardReadable, Locatable[Pol]):
@@ -743,7 +744,7 @@ def __init__(self, id_controller: Apple2Controller, name: str = "") -> None:
743744

744745
@AsyncStatus.wrap
745746
async def set(self, pol: Pol) -> None:
746-
await self.polarisation().set(pol)
747+
await self.polarisation().set(pol, timeout=MAXIMUM_MOVE_TIME)
747748

748749
async def locate(self) -> Location[Pol]:
749750
"""Return the current polarisation"""

src/dodal/devices/i10/i10_apple2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
)
1414

1515
from dodal.devices.apple2_undulator import (
16+
MAXIMUM_MOVE_TIME,
1617
Apple2,
1718
Apple2Controller,
1819
Apple2PhasesVal,
@@ -34,7 +35,6 @@
3435
MAXIMUM_GAP_MOTOR_POSITION = 100
3536
DEFAULT_JAW_PHASE_POLY_PARAMS = [1.0 / 7.5, -120.0 / 7.5]
3637
ALPHA_OFFSET = 180
37-
MAXIMUM_MOVE_TIME = 550 # There is no useful movements take longer than this.
3838

3939

4040
class I10EnergyMotorLookup(EnergyMotorLookup):
@@ -282,4 +282,4 @@ def __init__(
282282

283283
@AsyncStatus.wrap
284284
async def set(self, angle: float) -> None:
285-
await self.linear_arbitrary_angle().set(angle)
285+
await self.linear_arbitrary_angle().set(angle, timeout=MAXIMUM_MOVE_TIME)

tests/devices/i10/test_i10_apple2.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pickle
33
from collections.abc import Mapping
44
from unittest import mock
5-
from unittest.mock import MagicMock, Mock
5+
from unittest.mock import AsyncMock, MagicMock, Mock
66

77
import pytest
88
from bluesky.plans import scan
@@ -18,6 +18,7 @@
1818
)
1919

2020
from dodal.devices.apple2_undulator import (
21+
MAXIMUM_MOVE_TIME,
2122
BeamEnergy,
2223
EnabledDisabledUpper,
2324
InsertionDeviceEnergy,
@@ -303,6 +304,17 @@ async def test_fail_i10_apple2_controller_set_id_not_ready(
303304
)
304305

305306

307+
async def test_fail_i10_apple2_controller_set_energy_has_default(
308+
mock_id_energy: InsertionDeviceEnergy,
309+
mock_id_controller: I10Apple2Controller,
310+
):
311+
mock_id_controller.energy.set = AsyncMock()
312+
await mock_id_energy.set(600)
313+
mock_id_controller.energy.set.assert_awaited_once_with(
314+
600, timeout=MAXIMUM_MOVE_TIME
315+
)
316+
317+
306318
async def test_beam_energy_re_scan(
307319
run_engine: RunEngine,
308320
run_engine_documents: Mapping[str, list[dict]],
@@ -414,6 +426,18 @@ async def test_id_polarisation_set(
414426
assert float(gap.call_args[0][0]) == pytest.approx(expect_gap, 0.05)
415427

416428

429+
async def test_id_polarisation_set_has_default_timeout(
430+
mock_id_pol: InsertionDevicePolarisation,
431+
mock_id_controller: I10Apple2Controller,
432+
):
433+
set_mock_value(mock_id_controller._energy, 700)
434+
mock_id_controller.polarisation.set = AsyncMock()
435+
await mock_id_pol.set(Pol.LV)
436+
mock_id_controller.polarisation.set.assert_awaited_once_with(
437+
Pol.LV, timeout=MAXIMUM_MOVE_TIME
438+
)
439+
440+
417441
@pytest.mark.parametrize(
418442
"pol,energy, top_outer, top_inner, btm_inner,btm_outer",
419443
[
@@ -551,6 +575,17 @@ async def test_linear_arbitrary_pol_fail_read(
551575
)
552576

553577

578+
async def test_linear_arbitrary_pol_set_default_timeout(
579+
mock_linear_arbitrary_angle: LinearArbitraryAngle,
580+
mock_id_controller: I10Apple2Controller,
581+
):
582+
mock_id_controller.linear_arbitrary_angle.set = AsyncMock()
583+
await mock_linear_arbitrary_angle.set(60)
584+
mock_id_controller.linear_arbitrary_angle.set.assert_awaited_once_with(
585+
60, timeout=MAXIMUM_MOVE_TIME
586+
)
587+
588+
554589
@pytest.mark.parametrize(
555590
"poly",
556591
[18, -18, 12.01, -12.01],

0 commit comments

Comments
 (0)