Skip to content

Commit

Permalink
Make tests more stable
Browse files Browse the repository at this point in the history
  • Loading branch information
x42005e1f authored Dec 7, 2024
1 parent 6871a22 commit 7b404db
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions tests/test_mixed.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import asyncio
import threading

from concurrent.futures import ThreadPoolExecutor

import pytest

import janus
Expand Down Expand Up @@ -327,20 +329,18 @@ async def test_put_notifies_sync_not_empty(self):
loop = asyncio.get_running_loop()
q = janus.Queue()

futures = [
loop.run_in_executor(None, q.sync_q.get)
for _ in range(4)
]
with ThreadPoolExecutor(4) as executor:
for _ in range(4):
executor.submit(q.sync_q.get)

while q._sync_not_empty_waiting != 4:
await asyncio.sleep(0.001)
while q._sync_not_empty_waiting != 4:
await asyncio.sleep(0.001)

Check warning on line 337 in tests/test_mixed.py

View check run for this annotation

Codecov / codecov/patch

tests/test_mixed.py#L337

Added line #L337 was not covered by tests

q.sync_q.put_nowait(1)
q.async_q.put_nowait(2)
await loop.run_in_executor(None, q.sync_q.put, 3)
await q.async_q.put(4)
q.sync_q.put_nowait(1)
q.async_q.put_nowait(2)
await loop.run_in_executor(executor, q.sync_q.put, 3)
await q.async_q.put(4)

await asyncio.gather(*futures)
assert q.sync_q.empty()
await q.aclose()

Expand All @@ -354,7 +354,8 @@ async def test_put_notifies_async_not_empty(self):
for _ in range(4)
]

await asyncio.sleep(0)
while q._async_not_empty_waiting != 4:
await asyncio.sleep(0)

q.sync_q.put_nowait(1)
q.async_q.put_nowait(2)
Expand All @@ -372,20 +373,18 @@ async def test_get_notifies_sync_not_full(self):
q.sync_q.put_nowait(1)
q.sync_q.put_nowait(2)

futures = [
loop.run_in_executor(None, q.sync_q.put, object())
for _ in range(4)
]
with ThreadPoolExecutor(4) as executor:
for _ in range(4):
executor.submit(q.sync_q.put, object())

while q._sync_not_full_waiting != 4:
await asyncio.sleep(0.001)
while q._sync_not_full_waiting != 4:
await asyncio.sleep(0.001)

Check warning on line 381 in tests/test_mixed.py

View check run for this annotation

Codecov / codecov/patch

tests/test_mixed.py#L381

Added line #L381 was not covered by tests

q.sync_q.get_nowait()
q.async_q.get_nowait()
await loop.run_in_executor(None, q.sync_q.get)
await q.async_q.get()
q.sync_q.get_nowait()
q.async_q.get_nowait()
await loop.run_in_executor(executor, q.sync_q.get)
await q.async_q.get()

await asyncio.gather(*futures)
assert q.sync_q.qsize() == 2
await q.aclose()

Expand All @@ -401,7 +400,8 @@ async def test_get_notifies_async_not_full(self):
for _ in range(4)
]

await asyncio.sleep(0)
while q._async_not_full_waiting != 4:
await asyncio.sleep(0)

q.sync_q.get_nowait()
q.async_q.get_nowait()
Expand Down

0 comments on commit 7b404db

Please sign in to comment.