Skip to content

Commit

Permalink
Merge pull request #473 from ISISComputingGroup/retry_stop_motors_in_…
Browse files Browse the repository at this point in the history
…refl_tests

add retry when stopping motors in refl tests
  • Loading branch information
RaiBishal authored Jul 13, 2021
2 parents 7470455 + 3d7d229 commit 1fa0841
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions tests/refl.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,22 @@ def all_motors_in_set_mode(channel_access):
channel_access.set_pv_value(offset_freeze_switch_pv.format(motor), offset_freeze_switch)


def stop_motors_with_retry(channel_access, n_retry):
"""
Tries to stop all motors several times as this operation sometimes fails for simulated axes.
Args:
channel_access: The channel access interface to use
n_retry: The number of retries
"""
for _ in range(n_retry):
channel_access.set_pv_value("MOT:STOP:ALL", 1, wait=True)
if channel_access.get_pv_value("MOT:MOVING") == 0.0:
break
time.sleep(1)
self.ca_cs.assert_that_pv_is("MOT:MOVING", 0, timeout=5)


class ReflTests(unittest.TestCase):
"""
Tests for reflectometry server
Expand All @@ -143,8 +159,7 @@ def setUp(self):
self.ca_galil = ChannelAccess(default_timeout=30, device_prefix="MOT", default_wait_time=0.0)
self.ca_cs = ChannelAccess(default_timeout=30, device_prefix="CS", default_wait_time=0.0)
self.ca_no_prefix = ChannelAccess()
self.ca_cs.set_pv_value("MOT:STOP:ALL", 1)
self.ca_cs.assert_that_pv_is("MOT:MOVING", 0, timeout=60)
stop_motors_with_retry(self.ca_cs, 5)
with all_motors_in_set_mode(self.ca_galil):
self.ca.set_pv_value("BL:MODE:SP", "NR")
self.ca.set_pv_value("PARAM:S1:SP", 0)
Expand Down Expand Up @@ -388,7 +403,7 @@ def test_GIVEN_new_parameter_sp_WHEN_parameter_rbv_not_changing_THEN_parameter_c
value = value

self.ca.set_pv_value("PARAM:{}:SP".format(param), value)
self.ca_cs.set_pv_value("MOT:STOP:ALL", 1)
stop_motors_with_retry(self.ca_cs, 5)

self.ca.assert_that_pv_is("PARAM:{}:CHANGING".format(param), expected_value)

Expand All @@ -399,7 +414,7 @@ def test_GIVEN_new_parameter_sp_WHEN_parameter_rbv_outside_of_sp_target_toleranc
value = value

self.ca.set_pv_value("PARAM:{}:SP".format(param), value)
self.ca_cs.set_pv_value("MOT:STOP:ALL", 1)
stop_motors_with_retry(self.ca_cs, 5)

self.ca.assert_that_pv_is("PARAM:{}:RBV:AT_SP".format(param), expected_value)

Expand All @@ -410,7 +425,7 @@ def test_GIVEN_new_parameter_sp_WHEN_parameter_rbv_within_sp_target_tolerance_TH
value = value

self.ca.set_pv_value("PARAM:{}:SP".format(param), value)
self.ca_cs.set_pv_value("MOT:STOP:ALL", 1)
stop_motors_with_retry(self.ca_cs, 5)

self.ca.assert_that_pv_is("PARAM:{}:RBV:AT_SP".format(param), expected_value)

Expand Down

0 comments on commit 1fa0841

Please sign in to comment.