Skip to content

Commit

Permalink
TST: reduce odds of losing spurious race conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
tacaswell committed Oct 16, 2024
1 parent d964843 commit cb736e2
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions ophyd/tests/test_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,44 +750,40 @@ def test_signal_another_call_to_set_in_progress():


def test_signal_clear_set():
sig = Signal(name="sig", value=1)
sig.wait_for_connection()
class HackSignal(Signal):
def put(self, value, **kwargs):
...

st1 = sig.set(28, settle_time=0.2)
def _super_put(self, value, **kwargs):
super().put(value, **kwargs)

sig = HackSignal(name="sig", value=1)
sig._super_put(1)

st1 = sig.set(28)
with pytest.raises(RuntimeError):
assert not st1.done
sig.set(-1)

# call SIGNAL.clear_set() and trap the warning after RuntimeError is raised
with pytest.warns(UserWarning):
sig.clear_set()
assert not st1.done
assert not st1.success

sig._super_put(28)
wait(st1)
assert sig.get() == 28


def test_epicssignal_abandonedset():
pill = threading.Event()

class BrokenPutSignal(Signal):
"""put(value) ends with same ._readback value as before."""
"""put(value) that ignores input"""

def put(self, value, **kwargs):
previous_value = self._readback
super().put(value, **kwargs)
self._readback = previous_value
super().put(self._readback, **kwargs)
pill.set()

sig = BrokenPutSignal(name="sig", value=1)
sig.wait_for_connection()

with pytest.raises(AbandonedSet):
pill = threading.Event()

def cb():
time.sleep(0.1)
sig.clear_set()
pill.set()

threading.Thread(group=None, target=cb).start()
_set_and_wait(sig, sig.get() + 1, timeout=20, poison_pill=pill)
assert sig.get() == 1

0 comments on commit cb736e2

Please sign in to comment.