Skip to content

Commit

Permalink
added test for wait for set
Browse files Browse the repository at this point in the history
  • Loading branch information
ZohebShaikh committed Nov 18, 2024
1 parent d06c64c commit 4c45733
Showing 1 changed file with 47 additions and 6 deletions.
53 changes: 47 additions & 6 deletions tests/core/test_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ async def wait_and_set_proceeds():
async def check_set_and_wait():
await (await set_and_wait_for_value(signal, 1, timeout=0.1))

assert await signal.get_value() == 0
await asyncio.gather(wait_and_set_proceeds(), check_set_and_wait())
assert await signal.get_value() == 1


async def test_set_and_wait_for_value_different_set_and_read():
set_signal = epics_signal_rw(int, "pva://set", name="set-signal")
match_signal = epics_signal_r(str, "pva://read", name="match_signal")
match_signal = epics_signal_r(str, "pva://read", name="match-signal")
await set_signal.connect(mock=True)
await match_signal.connect(mock=True)

Expand All @@ -109,19 +110,59 @@ async def wait_and_set_read():
set_mock_value(match_signal, "test")

async def check_set_and_wait():
await (
await set_and_wait_for_other_value(
set_signal, 1, match_signal, "test", timeout=100
)
status = await set_and_wait_for_other_value(
set_signal,
1,
match_signal,
"test",
timeout=100,
wait_for_set_completion=True,
)
assert await match_signal.get_value() == "test"
assert status.done

await asyncio.gather(wait_and_set_read(), check_set_and_wait())
assert await set_signal.get_value() == 1


async def test_set_and_wait_behaviour_with_wait_for_set_completion_false():
set_signal = epics_signal_rw(int, "pva://set", name="set-signal")
match_signal = epics_signal_r(str, "pva://read", name="match-signal")
await set_signal.connect(mock=True)
await match_signal.connect(mock=True)
set_mock_put_proceeds(set_signal, False)

do_read_set = Event()

callback_on_mock_put(set_signal, lambda *args, **kwargs: do_read_set.set())

async def wait_and_set_read():
await do_read_set.wait()
set_mock_value(match_signal, "test")

async def check_set_and_wait():
status = await set_and_wait_for_other_value(
set_signal,
1,
match_signal,
"test",
timeout=10,
wait_for_set_completion=False,
)
assert not status.done
assert await match_signal.get_value() == "test"
set_mock_put_proceeds(set_signal, True)
await status
assert status.done
assert await set_signal.get_value() == 1

await asyncio.gather(wait_and_set_read(), check_set_and_wait())
assert await set_signal.get_value() == 1


async def test_set_and_wait_for_value_different_set_and_read_times_out():
set_signal = epics_signal_rw(int, "pva://set", name="set-signal")
match_signal = epics_signal_r(str, "pva://read", name="match_signal")
match_signal = epics_signal_r(str, "pva://read", name="match-signal")
await set_signal.connect(mock=True)
await match_signal.connect(mock=True)

Expand Down

0 comments on commit 4c45733

Please sign in to comment.