Skip to content

Commit

Permalink
(#117) (#45) add timeout test
Browse files Browse the repository at this point in the history
  • Loading branch information
dperl-dls committed Apr 15, 2024
1 parent 3dc36c9 commit 7a5f3ee
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion tests/core/test_async_status_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ async def set(self, val):
self.sig._backend._set_value(val) # type: ignore


class ASTestDeviceTimeoutSet(ASTestDevice):
@WatchableAsyncStatus.wrap
async def set(self, val, timeout_s=0.01):
assert self._staged
await asyncio.sleep(0.01)
self.sig._backend._set_value(val - 1) # type: ignore
await asyncio.sleep(0.01)
yield WatcherUpdate(1, 1, 1)
await asyncio.sleep(0.01)
yield WatcherUpdate(1, 1, 1)


class ASTestDeviceIteratorSet(ASTestDevice):
def __init__(
self, name: str = "", values=[1, 2, 3, 4, 5], complete_set: bool = True
Expand Down Expand Up @@ -197,7 +209,7 @@ async def test_asyncstatus_wraps_set_iterator_with_class_or_func_watcher(RE):
assert sum(w.updates) == 21


async def test_asyncstatus_wraps_failing_set_iterator_(RE):
async def test_asyncstatus_wraps_failing_set_iterator(RE):
td = ASTestDeviceIteratorSet(values=[1, 2, 3], complete_set=False)
await td.connect()
await td.stage()
Expand All @@ -213,3 +225,14 @@ async def test_asyncstatus_wraps_failing_set_iterator_(RE):
assert not st.success
assert isinstance(st.exception(), SetFailed)
assert len(updates) == 3


async def test_asyncstatus_times_out(RE):
td = ASTestDeviceTimeoutSet()
await td.connect()
await td.stage()
st = td.set(6, timeout_s=0.01)
while not st.done:
await asyncio.sleep(0.01)
assert not st.success
assert isinstance(st.exception(), TimeoutError)

0 comments on commit 7a5f3ee

Please sign in to comment.