Skip to content

Commit

Permalink
Fix tests for contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicOram committed Oct 10, 2024
1 parent fb5887e commit d38a2fd
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions tests/test_aioca.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,25 +622,24 @@ def test_import_in_a_different_thread(ioc: subprocess.Popen) -> None:
assert output.strip() == b"42"


def test_read_pvs_from_different_threads(ioc: subprocess.Popen) -> None:
@pytest.mark.asyncio
async def test_read_pvs_from_different_threads(ioc: subprocess.Popen) -> None:
wait_for_ioc(ioc)
returned_values = []
threads = []

returned_values.append(await caget(LONGOUT, timeout=0.5))

async def get_value():
returned_values.append(await caget(LONGOUT, timeout=0.5))
await asyncio.sleep(1)

for _ in range(2):
# Run event loop in a different thread
t = threading.Thread(
target=asyncio.new_event_loop().run_until_complete, args=[get_value()]
)
threads.append(t)
t.start()

for t in threads:
t.join()
t = threading.Thread(
target=asyncio.new_event_loop().run_until_complete, args=[get_value()]
)
threads.append(t)
t.start()
t.join()

assert len(returned_values) == 2

Expand Down

0 comments on commit d38a2fd

Please sign in to comment.